Created
September 13, 2014 17:16
-
-
Save bbengfort/4d401751da075c64fdd4 to your computer and use it in GitHub Desktop.
In Class example for Georgetown Data Analytics (Software Engineering) Cohort 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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