Skip to content

Instantly share code, notes, and snippets.

@bbengfort
Created September 13, 2014 17:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bbengfort/4d401751da075c64fdd4 to your computer and use it in GitHub Desktop.
Save bbengfort/4d401751da075c64fdd4 to your computer and use it in GitHub Desktop.
In Class example for Georgetown Data Analytics (Software Engineering) Cohort 2
import json
import requests
weather_url = "http://api.openweathermap.org/data/2.5/weather?q="
def kelvin_to_fahr(temp):
return ((9/5.0) * (temp-273) + 32)
def get_weather(city):
url = weather_url + city
response = requests.get(url)
if response.status_code == 200:
return response.json()
else:
print "Could not fetch the weather for some reason."
def get_temp(city):
weather = get_weather(city)
temp = kelvin_to_fahr(weather['main']['temp'])
return "The temperature in %s is %0.2f degrees Fahrenheit" % (city, temp)
if __name__ == '__main__':
while True:
try:
print get_temp(raw_input("Enter City: "))
except KeyboardInterrupt:
print "Quitting!"
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment