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

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?


In [11]:
import requests 
# api request for bethesda, maryland 
response = requests.get('https://api.forecast.io/forecast/a197f06e1906b1a937ad31d4378b8939/38.9847, -77.0947')
data = response.json()
current = data['currently']
current


Out[11]:
{'apparentTemperature': 83.54,
 'cloudCover': 0.13,
 'dewPoint': 61.37,
 'humidity': 0.48,
 'icon': 'clear-day',
 'nearestStormBearing': 181,
 'nearestStormDistance': 191,
 'ozone': 309.78,
 'precipIntensity': 0,
 'precipProbability': 0,
 'pressure': 1018.64,
 'summary': 'Clear',
 'temperature': 82.95,
 'time': 1468255781,
 'visibility': 10,
 'windBearing': 310,
 'windSpeed': 1.05}

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


In [14]:
diff = current['apparentTemperature'] - current['temperature'] 
print('The current windspeed is', current['windSpeed'],"miles per hour.")
print('It feels', diff, 'degrees warmer than it actually is.')


The current windspeed is 1.05 miles per hour.
It feels 0.5900000000000034 degrees warmer than it actually is.

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 [42]:
daily = data['daily']['data']
today = daily[0]
today_moonphase = today['moonPhase']

if today_moonphase < .25: 
    moonphase = 'new moon' 
elif today_moonphase < 0.5:
    moonphase = 'first quarter moon' 
elif today_moonphase < 0.75:
    moonphase = 'full moon' 
else:
    moonphase = 'last quarter moon' 
    
print('Reported moon phase from Dark Sky forecast is', today_moonphase)
print('So, currently, the', moonphase, 'is visible.')


Reported moon phase from Dark Sky forecast is 0.24
So, currently, the new moon is visible.

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


In [43]:
highlow_tempdiff = today['temperatureMax'] - today['temperatureMin']
print('The difference between the high and low temperatures for today is', highlow_tempdiff, 'degrees.')


The difference between the high and low temperatures for today is 22.159999999999997 degrees.

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 [62]:
for item in daily: 
    daily_hightemp = item['temperatureMax']
    if daily_hightemp < 70: 
        tempdescription = 'COLD'
    elif daily_hightemp < 85: 
        tempdescription = 'WARM'
    else: 
        tempdescription = 'HOT'

    print('The high temp is', daily_hightemp, 'so it is', tempdescription)


The high temp is 87.25 so it is HOT
The high temp is 87.6 so it is HOT
The high temp is 86.14 so it is HOT
The high temp is 96.17 so it is HOT
The high temp is 94.83 so it is HOT
The high temp is 91.91 so it is HOT
The high temp is 85.88 so it is HOT
The high temp is 84.84 so it is 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 [74]:
response = requests.get('https://api.forecast.io/forecast/a197f06e1906b1a937ad31d4378b8939/25.7617,-80.1918')
data = response.json()

hourly = data['hourly']['data']

for item in hourly: 
    if item['cloudCover'] < .5: 
        print('It is', item['temperature'], 'degrees and cloudy')
    else: 
        print('It is', item['temperature'], 'degrees')


It is 90.53 degrees and cloudy
It is 89.03 degrees and cloudy
It is 89.36 degrees
It is 89.3 degrees
It is 88.47 degrees and cloudy
It is 87.26 degrees and cloudy
It is 85.73 degrees
It is 84.51 degrees
It is 83.85 degrees and cloudy
It is 83.53 degrees and cloudy
It is 83.29 degrees and cloudy
It is 83.06 degrees and cloudy
It is 82.64 degrees and cloudy
It is 82.25 degrees and cloudy
It is 82.12 degrees and cloudy
It is 81.69 degrees and cloudy
It is 81.1 degrees and cloudy
It is 82.04 degrees and cloudy
It is 82.81 degrees and cloudy
It is 83.72 degrees and cloudy
It is 85.22 degrees and cloudy
It is 87.36 degrees and cloudy
It is 90.13 degrees
It is 91.9 degrees
It is 91.16 degrees and cloudy
It is 90.64 degrees and cloudy
It is 90.08 degrees and cloudy
It is 89.43 degrees and cloudy
It is 88.65 degrees and cloudy
It is 87.7 degrees and cloudy
It is 86.69 degrees and cloudy
It is 85.92 degrees and cloudy
It is 85.5 degrees and cloudy
It is 85.23 degrees and cloudy
It is 84.8 degrees and cloudy
It is 84.12 degrees and cloudy
It is 83.31 degrees and cloudy
It is 82.57 degrees and cloudy
It is 82.02 degrees and cloudy
It is 81.67 degrees and cloudy
It is 82.21 degrees and cloudy
It is 82.84 degrees and cloudy
It is 83.43 degrees and cloudy
It is 84.05 degrees and cloudy
It is 84.9 degrees and cloudy
It is 86.15 degrees and cloudy
It is 87.44 degrees and cloudy
It is 88.57 degrees and cloudy
It is 89.73 degrees and cloudy

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

Tip: You'll need to use UNIX time, which is the number of seconds since January 1, 1970. Google can help you convert a normal date! Tip: You'll want to use Forecast.io's "time machine" API at https://developer.forecast.io/docs/v2


In [121]:
response1980 = requests.get('https://api.forecast.io/forecast/a197f06e1906b1a937ad31d4378b8939/40.7829,-73.9654,346550400')
data1980 = response1980.json()
christmasday1980 = data1980['daily']['data'][0]

print('It was', christmasday1980['temperatureMax'], 'degrees on Christmas Day, 1980.')

response1990 = requests.get('https://api.forecast.io/forecast/a197f06e1906b1a937ad31d4378b8939/40.7829,-73.9654,662083200')
data1990 = response1990.json()
christmasday1990 = data1990['daily']['data'][0]

print('It was', christmasday1990['temperatureMax'], 'degrees on Christmas Day, 1990.')

response2000 = requests.get('https://api.forecast.io/forecast/a197f06e1906b1a937ad31d4378b8939/40.7829,-73.9654,976838400')
data2000 = response2000.json()
christmasday2000 = data2000['daily']['data'][0]

print('It was', christmasday2000['temperatureMax'], 'degrees on Christmas Day, 2000.')


It was 36.95 degrees on Christmas Day, 1980.
It was 59.87 degrees on Christmas Day, 1990.
It was 47.87 degrees on Christmas Day, 2000.