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 [1]:
    
#api KEY =  c9d64e80aa02ca113562a075e57256d7
https://api.forecast.io/forecast/c9d64e80aa02ca113562a075e57256d7/10.4806,66.9036
    
    
In [2]:
    
import requests
response = requests.get("https://api.forecast.io/forecast/c9d64e80aa02ca113562a075e57256d7/10.4806,66.9036")
forecast = response.json()
print(forecast.keys())
    
    
In [3]:
    
print(forecast['timezone']) #yeap, this is my country's timezone
    
    
In [4]:
    
print(forecast['latitude'],forecast['longitude'] ) #nothing different with the latitude and longitude
    
    
In [5]:
    
print(forecast['currently'])
    
    
In [6]:
    
print("The actual current wind speed is", forecast['currently']['windSpeed'], "miles per hour")
    
    
In [7]:
    
print("Right know in Caracas the temperature feels like",forecast['currently']['apparentTemperature'])
    
    
In [8]:
    
print("Right know in Caracas the temperature is",forecast['currently']['temperature'])
    
    
In [9]:
    
print("It feels", forecast['currently']['apparentTemperature']-forecast['currently']['temperature'], "degrees warmer than the actual temperature")
    
    
In [10]:
    
print(forecast['daily'].keys())
    
    
In [11]:
    
forecast['daily']['data']
    
    Out[11]:
In [12]:
    
print(type(forecast['daily']['data']))
print(forecast['daily']['data'][0])
    
    
In [13]:
    
first_daily_forecast = forecast['daily']['data']
    
In [14]:
    
for item in first_daily_forecast[:1]: 
    print("In the first daily forecast", item['moonPhase'], "of the moon is currently visible")
    
    
In [15]:
    
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 of", item['temperatureMax']-item['temperatureMin'],"degrees Fahrenheit" )
    
    
In [16]:
    
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 will not be as hot as it usually is!")
    
    
In [17]:
    
import requests
response = requests.get("https://api.forecast.io/forecast/c9d64e80aa02ca113562a075e57256d7/25.7742700,-80.1936600")
forecast_miami = response.json()
print(forecast_miami.keys())
    
    
In [18]:
    
print(type(forecast_miami['hourly']))
print(forecast_miami['hourly'].keys())
print(forecast_miami['hourly']['data'][0])
forecast_miami_today = forecast_miami['hourly']['data']
    
    
In [19]:
    
print("This is how the weather in Miami will look in the next hours")
for item in forecast_miami_today:
    if item['cloudCover'] > 0.5:
        print("It will be", item['temperature'],"degrees Farenheit and cloudy!")
    else:
        print("It will be", item['temperature'], "degrees Farenheit")
    
    
In [20]:
    
#UNIX TIME 1980 : 346550400
#1990: 662083200
#2000:977702400
    
In [21]:
    
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 [22]:
    
print(forecast_1980['daily'].keys())
    
    
In [23]:
    
print(forecast_1980['daily']['data'])
    
    
In [24]:
    
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")
    
    
TA-Stephan: Close, but these should all be 40.7829,-73.9654,662083200
not
40.7829,73.9654,662083200 (missed the negative)
In [25]:
    
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 [26]:
    
christmas_temp_1990 = forecast_1990['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 [31]:
    
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 [32]:
    
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")
    
    
In [ ]:
    
    
In [ ]: