In [1]:
import requests
#apikey='4230d91e7452245b2479aec2fc16870d'

1) Make a request from the Forecast.io API for where you were born (or lived, or want to visit!).


In [8]:
# SEOUL = '37.532600,127.024612'
response = requests.get("https://api.forecast.io/forecast/4230d91e7452245b2479aec2fc16870d/37.532600,127.024612")
data = response.json()

In [10]:
data.keys()


Out[10]:
dict_keys(['daily', 'hourly', 'timezone', 'currently', 'flags', 'latitude', 'longitude', 'offset'])

In [11]:
data['timezone']


Out[11]:
'Asia/Seoul'

2) What's the current wind speed? How much warmer does it feel than it actually is?


In [13]:
# Wind speed
data['currently']['windSpeed']


Out[13]:
5.09

In [15]:
# How much warmer does it feel than it actually is
data['currently']['apparentTemperature']-data['currently']['temperature']


Out[15]:
0.0

3) The first daily forecast is the forecast for today. For the place you decided on up above, how much of the moon is currently visible?


In [44]:
daily = data['daily']['data']
print (daily[0]['moonPhase'])


0.27

4) What's the difference between the high and low temperatures for today?


In [45]:
daily[0]['temperatureMax']-daily[0]['temperatureMin']


Out[45]:
23.78

5) Loop through the daily forecast, printing out the next week's worth of predictions. I'd like to know the high temperature for each day, and whether it's hot, warm, or cold, based on what temperatures you think are hot, warm or cold.


In [51]:
for temmax in daily:
    print (temmax['temperatureMax'])
    if temmax['temperatureMax'] <80:
        print ("Oh, it's cold")
    else:
        print("Oh, it's warm")


82.44
Oh, it's warm
84.19
Oh, it's warm
81.25
Oh, it's warm
75.64
Oh, it's cold
82.15
Oh, it's warm
80.78
Oh, it's warm
79.92
Oh, it's cold
83.89
Oh, it's warm

6) What's the weather looking like for the rest of today in Miami, Florida? I'd like to know the temperature for every hour, and if it's going to have cloud cover of more than 0.5 say "{temperature} and cloudy" instead of just the temperature.


In [52]:
# Miami, Florida = 25.787676,-80.224145
response = requests.get("https://api.forecast.io/forecast/4230d91e7452245b2479aec2fc16870d/25.787676,-80.224145")
data = response.json()

In [53]:
data['timezone']


Out[53]:
'America/New_York'

In [61]:
hourly = data['hourly']['data']
for weather in hourly:
    if weather['cloudCover'] > 0.5:
        print (weather['temperature'],"and cloudy")
    else:
        print(weather['temperature'])


81.16
80.27
79.55
78.54
77.55
76.35
75.69 and cloudy
75.32
76.57
78.86
81.36
83.17
84.64
85.94
87.43
88.53
87.91
86.73
85.83
84.73
83.79
82.77
81.33
80.09
80.46
79.69
78.85
77.91
76.82
75.93
76.59
77.77
79
80.12
81.51
83.3
85.05
86.44
87.7
88.45
87.65
86.14
84.91
83.82
82.94
82.37
81.89
81.37
80.76

7) What was the temperature in Central Park on Christmas Day, 1980? How about 1990? 2000?


In [80]:
# 1980-12-25 = '346550400'
# Central Park = '40.785091,-73.968285'
response = requests.get("https://api.forecast.io/forecast/4230d91e7452245b2479aec2fc16870d/40.785091,-73.968285,346550400")
data = response.json()

In [81]:
data['currently']['temperature']
print ("It was", data['currently']['temperature'], "degree in Central Park on Christmas Day in 1980")


It was 33.95 degree in Central Park on Christmas Day in 1980

In [84]:
# 1990-12-25 = '662083200'
response = requests.get("https://api.forecast.io/forecast/4230d91e7452245b2479aec2fc16870d/40.785091,-73.968285,662083200")
data = response.json()

In [85]:
print ("It was", data['currently']['temperature'], "degree in Central Park on Christmas Day in 1990")


It was 36.71 degree in Central Park on Christmas Day in 1990

In [86]:
# 2000-12-25 = '977702400'
response = requests.get("https://api.forecast.io/forecast/4230d91e7452245b2479aec2fc16870d/40.785091,-73.968285,977702400")
data = response.json()

In [87]:
print ("It was", data['currently']['temperature'], "degree in Central Park on Christmas Day in 2000")


It was 20.77 degree in Central Park on Christmas Day in 2000