from __future__ import print_function | |
import json | |
import urllib2 | |
def lambda_handler(event, context): | |
print("Received event: " + json.dumps(event, indent=2)) | |
if 'city' not in event.keys(): | |
return "Please Enter a City" | |
api_base_url = "http://api.openweathermap.org/data/2.5/weather?q=" | |
api_base_url += event['city'] | |
api_base_url += "&APPID=38a5ea89e1ee220a5c7dbdbd04c9a67d" | |
print(api_base_url) | |
# return api_base_url | |
response = urllib2.urlopen(api_base_url).read() | |
res = json.loads(response) | |
print(res) | |
print(res["cod"]) | |
if res['cod'] == 200: | |
return res['weather'][0] | |
else: | |
return "API Responded with " + res['cod'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment