Tip: Once you've imported the JSON into a variable, check the timezone's name to make sure it seems like it got the right part of the world! Tip 2: How is north vs. south and east vs. west latitude/longitude represented? Is it the normal North/South/East/West? Graded = 6/7
In [35]:
#api KEY = c9d64e80aa02ca113562a075e57256d7
https://api.forecast.io/forecast/c9d64e80aa02ca113562a075e57256d7/10.4806,66.9036
In [36]:
import requests
response = requests.get("https://api.forecast.io/forecast/c9d64e80aa02ca113562a075e57256d7/10.4806,66.9036")
forecast = response.json()
print(forecast.keys())
In [5]:
print(forecast['timezone'])
In [7]:
print(forecast['latitude'],forecast['longitude'] )
In [8]:
print(forecast['currently'])
In [9]:
print("The current wind speed is", forecast['currently']['windSpeed'], "miles per hour")
In [10]:
print("Right know in Caracas the temperature feels like",forecast['currently']['apparentTemperature'])
In [11]:
print("Right know in Caracas the temperature is",forecast['currently']['temperature'])
In [12]:
print("It feels about", forecast['currently']['apparentTemperature']-forecast['currently']['temperature'], "degrees warmer than the actual temperature")
In [13]:
print(forecast['daily'].keys())
In [14]:
forecast['daily']['data']
In [15]:
print(type(forecast['daily']['data']))
print(forecast['daily']['data'][0])
In [16]:
first_daily_forecast = forecast['daily']['data']
In [17]:
for item in first_daily_forecast[:1]:
print("In the first daily forecast", item['moonPhase'], "of the moon is currently visible")
In [19]:
for item in first_daily_forecast[:1]:
print("The min temperature for the day is:", item['temperatureMin'], "degrees Fahrenheit")
print("The max temperature for the day is:", item['temperatureMax'], "degrees Fahrenheit")
print("The difference between min and max temperatures is", item['temperatureMax']-item['temperatureMin'],"degrees Fahrenheit" )
In [20]:
for item in first_daily_forecast:
if item['temperatureMax'] > 80:
print("The high temperature for today is", item['temperatureMax'],"degrees Farenheit" )
print("It is going to be hot.")
else:
print("The high temperature for today is", item['temperatureMax'],"degrees Farenheit" )
print("It won't be as hot as it normally is, luckily.")
In [21]:
import requests
response = requests.get("https://api.forecast.io/forecast/c9d64e80aa02ca113562a075e57256d7/25.7742700,-80.1936600")
miami_forecast = response.json()
print(forecast_miami.keys())
In [22]:
print(type(miami_forecast['hourly']))
print(miami_forecast['hourly'].keys())
print(miami_forecast['hourly']['data'][0])
miami_forecast_today = miami_forecast['hourly']['data']
In [23]:
print("Here is an estimation of how the weather in Miami will look within the next few hours")
for item in forecast_miami_today:
if item['cloudCover'] > 0.5:
print("It will be", item['temperature'],"degrees Farenheit and overcast.")
else:
print("It will be", item['temperature'], "degrees Farenheit")
In [31]:
import requests
response = requests.get("https://api.forecast.io/forecast/c9d64e80aa02ca113562a075e57256d7/40.7829,73.9654,346550400")
forecast_1980 = response.json()
print(forecast_1980.keys())
In [25]:
print(1980_forecast['daily'].keys())
In [32]:
print(forecast_1980['daily']['data'])
In [27]:
christmas_temp_1980 = forecast_1980['daily']['data']
for item in christmas_temp_1980:
print("On Christmas Day, 1980, temperatures ranged between", item['temperatureMax'], "and", item['temperatureMin'], "degrees Farenheit at Central Park")
In [28]:
import requests
response = requests.get("https://api.forecast.io/forecast/c9d64e80aa02ca113562a075e57256d7/40.7829,73.9654,662083200")
forecast_1990 = response.json()
print(forecast_1990.keys())
In [29]:
christmas_temp_1990 = 1990_forecast['daily']['data']
for item in christmas_temp_1990:
print("On Christmas Day, 1990, temperatures ranged between", item['temperatureMax'], "and", item['temperatureMin'], "degrees Farenheit at Central Park")
In [30]:
import requests
response = requests.get("https://api.forecast.io/forecast/c9d64e80aa02ca113562a075e57256d7/40.7829,73.9654,977702400")
forecast_2000 = response.json()
print(forecast_2000.keys())
In [ ]:
christmas_temp_2000 = forecast_2000['daily']['data']
for item in christmas_temp_2000:
print("On Christmas Day, 2000, temperatures ranged between", item['temperatureMax'], "and", item['temperatureMin'], "degrees Farenheit at Central Park")