Skip to content

Instantly share code, notes, and snippets.

@jshin49
Created August 24, 2016 11:49
Show Gist options
  • Save jshin49/959833ac2a05ca2e692fb4d4d8de9898 to your computer and use it in GitHub Desktop.
Save jshin49/959833ac2a05ca2e692fb4d4d8de9898 to your computer and use it in GitHub Desktop.
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