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?

Graded = 6/7


In [1]:
#api KEY =  c9d64e80aa02ca113562a075e57256d7

https://api.forecast.io/forecast/c9d64e80aa02ca113562a075e57256d7/10.4806,66.9036


  File "<ipython-input-1-f3a60b769640>", line 3
    https://api.forecast.io/forecast/c9d64e80aa02ca113562a075e57256d7/10.4806,66.9036
         ^
SyntaxError: invalid syntax

In [2]:
import requests
response = requests.get("https://api.forecast.io/forecast/c9d64e80aa02ca113562a075e57256d7/10.4806,66.9036")
forecast = response.json()
print(forecast.keys())


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

In [3]:
print(forecast['timezone']) #yeap, this is my country's timezone


Etc/GMT-4

In [4]:
print(forecast['latitude'],forecast['longitude'] ) #nothing different with the latitude and longitude


10.4806 66.9036

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


In [5]:
print(forecast['currently'])


{'precipIntensity': 0.0214, 'dewPoint': 76.03, 'windSpeed': 19.38, 'humidity': 0.77, 'apparentTemperature': 92.7, 'time': 1466217553, 'cloudCover': 0.95, 'windBearing': 271, 'ozone': 268.55, 'temperature': 83.88, 'summary': 'Light Rain', 'precipType': 'rain', 'pressure': 1010.35, 'icon': 'rain', 'precipProbability': 0.54}

In [6]:
print("The actual current wind speed is", forecast['currently']['windSpeed'], "miles per hour")


The actual current wind speed is 19.38 miles per hour

In [7]:
print("Right know in Caracas the temperature feels like",forecast['currently']['apparentTemperature'])


Right know in Caracas the temperature feels like 92.7

In [8]:
print("Right know in Caracas the temperature is",forecast['currently']['temperature'])


Right know in Caracas the temperature is 83.88

In [9]:
print("It feels", forecast['currently']['apparentTemperature']-forecast['currently']['temperature'], "degrees warmer than the actual temperature")


It feels 8.820000000000007 degrees warmer than the actual temperature

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 [10]:
print(forecast['daily'].keys())


dict_keys(['data', 'summary', 'icon'])

In [11]:
forecast['daily']['data']


Out[11]:
[{'apparentTemperatureMax': 93.97,
  'apparentTemperatureMaxTime': 1466244000,
  'apparentTemperatureMin': 92.48,
  'apparentTemperatureMinTime': 1466258400,
  'cloudCover': 0.93,
  'dewPoint': 76.35,
  'humidity': 0.78,
  'icon': 'rain',
  'moonPhase': 0.43,
  'ozone': 266.59,
  'precipIntensity': 0.0087,
  'precipIntensityMax': 0.0231,
  'precipIntensityMaxTime': 1466218800,
  'precipProbability': 0.55,
  'precipType': 'rain',
  'pressure': 1009.9,
  'summary': 'Light rain throughout the day.',
  'sunriseTime': 1466212366,
  'sunsetTime': 1466258216,
  'temperatureMax': 84.15,
  'temperatureMaxTime': 1466244000,
  'temperatureMin': 83.63,
  'temperatureMinTime': 1466258400,
  'time': 1466193600,
  'windBearing': 273,
  'windSpeed': 19},
 {'apparentTemperatureMax': 102.35,
  'apparentTemperatureMaxTime': 1466316000,
  'apparentTemperatureMin': 88.2,
  'apparentTemperatureMinTime': 1466362800,
  'cloudCover': 0.99,
  'dewPoint': 76.33,
  'humidity': 0.77,
  'icon': 'rain',
  'moonPhase': 0.46,
  'ozone': 267.09,
  'precipIntensity': 0.0106,
  'precipIntensityMax': 0.0225,
  'precipIntensityMaxTime': 1466348400,
  'precipProbability': 0.54,
  'precipType': 'rain',
  'pressure': 1009.26,
  'summary': 'Light rain throughout the day.',
  'sunriseTime': 1466298777,
  'sunsetTime': 1466344629,
  'temperatureMax': 87.41,
  'temperatureMaxTime': 1466316000,
  'temperatureMin': 82.13,
  'temperatureMinTime': 1466362800,
  'time': 1466280000,
  'windBearing': 274,
  'windSpeed': 21.86},
 {'apparentTemperatureMax': 99.17,
  'apparentTemperatureMaxTime': 1466449200,
  'apparentTemperatureMin': 88.74,
  'apparentTemperatureMinTime': 1466373600,
  'cloudCover': 0.95,
  'dewPoint': 75.63,
  'humidity': 0.77,
  'icon': 'rain',
  'moonPhase': 0.48,
  'ozone': 269.04,
  'precipIntensity': 0.0136,
  'precipIntensityMax': 0.0215,
  'precipIntensityMaxTime': 1466370000,
  'precipProbability': 0.54,
  'precipType': 'rain',
  'pressure': 1007.88,
  'summary': 'Light rain throughout the day.',
  'sunriseTime': 1466385189,
  'sunsetTime': 1466431042,
  'temperatureMax': 86.3,
  'temperatureMaxTime': 1466449200,
  'temperatureMin': 82.31,
  'temperatureMinTime': 1466373600,
  'time': 1466366400,
  'windBearing': 271,
  'windSpeed': 23.22},
 {'apparentTemperatureMax': 98.85,
  'apparentTemperatureMaxTime': 1466510400,
  'apparentTemperatureMin': 88.62,
  'apparentTemperatureMinTime': 1466467200,
  'cloudCover': 0.97,
  'dewPoint': 76.11,
  'humidity': 0.77,
  'icon': 'rain',
  'moonPhase': 0.53,
  'ozone': 269.69,
  'precipIntensity': 0.0252,
  'precipIntensityMax': 0.0424,
  'precipIntensityMaxTime': 1466467200,
  'precipProbability': 0.61,
  'precipType': 'rain',
  'pressure': 1007.15,
  'summary': 'Light rain throughout the day.',
  'sunriseTime': 1466471601,
  'sunsetTime': 1466517454,
  'temperatureMax': 86.28,
  'temperatureMaxTime': 1466510400,
  'temperatureMin': 82.28,
  'temperatureMinTime': 1466467200,
  'time': 1466452800,
  'windBearing': 260,
  'windSpeed': 25.48},
 {'apparentTemperatureMax': 96.59,
  'apparentTemperatureMaxTime': 1466600400,
  'apparentTemperatureMin': 90.09,
  'apparentTemperatureMinTime': 1466586000,
  'cloudCover': 0.97,
  'dewPoint': 75.63,
  'humidity': 0.76,
  'icon': 'rain',
  'moonPhase': 0.56,
  'ozone': 266.75,
  'precipIntensity': 0.0473,
  'precipIntensityMax': 0.0711,
  'precipIntensityMaxTime': 1466604000,
  'precipProbability': 0.67,
  'precipType': 'rain',
  'pressure': 1007.47,
  'summary': 'Rain throughout the day.',
  'sunriseTime': 1466558013,
  'sunsetTime': 1466603866,
  'temperatureMax': 85.54,
  'temperatureMaxTime': 1466600400,
  'temperatureMin': 82.96,
  'temperatureMinTime': 1466586000,
  'time': 1466539200,
  'windBearing': 255,
  'windSpeed': 28.43},
 {'apparentTemperatureMax': 95.26,
  'apparentTemperatureMaxTime': 1466625600,
  'apparentTemperatureMin': 89.34,
  'apparentTemperatureMinTime': 1466647200,
  'cloudCover': 0.94,
  'dewPoint': 75.1,
  'humidity': 0.75,
  'icon': 'rain',
  'moonPhase': 0.59,
  'ozone': 262.97,
  'precipIntensity': 0.0516,
  'precipIntensityMax': 0.0757,
  'precipIntensityMaxTime': 1466654400,
  'precipProbability': 0.67,
  'precipType': 'rain',
  'pressure': 1007.63,
  'summary': 'Rain throughout the day.',
  'sunriseTime': 1466644426,
  'sunsetTime': 1466690277,
  'temperatureMax': 85.25,
  'temperatureMaxTime': 1466625600,
  'temperatureMin': 82.73,
  'temperatureMinTime': 1466647200,
  'time': 1466625600,
  'windBearing': 256,
  'windSpeed': 28.56},
 {'apparentTemperatureMax': 94.47,
  'apparentTemperatureMaxTime': 1466712000,
  'apparentTemperatureMin': 91.16,
  'apparentTemperatureMinTime': 1466794800,
  'cloudCover': 0.98,
  'dewPoint': 75.54,
  'humidity': 0.76,
  'icon': 'rain',
  'moonPhase': 0.63,
  'ozone': 264.63,
  'precipIntensity': 0.018,
  'precipIntensityMax': 0.0466,
  'precipIntensityMaxTime': 1466791200,
  'precipProbability': 0.62,
  'precipType': 'rain',
  'pressure': 1007.43,
  'summary': 'Light rain throughout the day.',
  'sunriseTime': 1466730839,
  'sunsetTime': 1466776688,
  'temperatureMax': 84.99,
  'temperatureMaxTime': 1466712000,
  'temperatureMin': 83.51,
  'temperatureMinTime': 1466794800,
  'time': 1466712000,
  'windBearing': 252,
  'windSpeed': 28.61},
 {'apparentTemperatureMax': 93.14,
  'apparentTemperatureMaxTime': 1466866800,
  'apparentTemperatureMin': 90.34,
  'apparentTemperatureMinTime': 1466812800,
  'cloudCover': 0.96,
  'dewPoint': 75.09,
  'humidity': 0.75,
  'icon': 'rain',
  'moonPhase': 0.66,
  'ozone': 264.64,
  'precipIntensity': 0.014,
  'precipIntensityMax': 0.0341,
  'precipIntensityMaxTime': 1466798400,
  'precipProbability': 0.59,
  'precipType': 'rain',
  'pressure': 1007.37,
  'summary': 'Light rain throughout the day.',
  'sunriseTime': 1466817252,
  'sunsetTime': 1466863099,
  'temperatureMax': 84.39,
  'temperatureMaxTime': 1466866800,
  'temperatureMin': 83.14,
  'temperatureMinTime': 1466812800,
  'time': 1466798400,
  'windBearing': 256,
  'windSpeed': 28.14}]

In [12]:
print(type(forecast['daily']['data']))
print(forecast['daily']['data'][0])


<class 'list'>
{'precipIntensity': 0.0087, 'precipIntensityMaxTime': 1466218800, 'windSpeed': 19, 'precipType': 'rain', 'sunriseTime': 1466212366, 'ozone': 266.59, 'apparentTemperatureMaxTime': 1466244000, 'moonPhase': 0.43, 'temperatureMinTime': 1466258400, 'pressure': 1009.9, 'temperatureMaxTime': 1466244000, 'dewPoint': 76.35, 'sunsetTime': 1466258216, 'humidity': 0.78, 'precipIntensityMax': 0.0231, 'time': 1466193600, 'cloudCover': 0.93, 'windBearing': 273, 'temperatureMin': 83.63, 'apparentTemperatureMin': 92.48, 'temperatureMax': 84.15, 'precipProbability': 0.55, 'apparentTemperatureMax': 93.97, 'summary': 'Light rain throughout the day.', 'apparentTemperatureMinTime': 1466258400, 'icon': 'rain'}

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 the first daily forecast 0.43 of the moon is currently visible

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


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" )


The min temperature for the day is: 83.63 degrees Fahrenheit
The max temperature for the day is: 84.15 degrees Fahrenheit
The difference between min and max temperatures is of 0.5200000000000102 degrees Fahrenheit

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 [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!")


The high temperature for today is 84.15 degrees Farenheit
It is going to be HOT!
The high temperature for today is 87.41 degrees Farenheit
It is going to be HOT!
The high temperature for today is 86.3 degrees Farenheit
It is going to be HOT!
The high temperature for today is 86.28 degrees Farenheit
It is going to be HOT!
The high temperature for today is 85.54 degrees Farenheit
It is going to be HOT!
The high temperature for today is 85.25 degrees Farenheit
It is going to be HOT!
The high temperature for today is 84.99 degrees Farenheit
It is going to be HOT!
The high temperature for today is 84.39 degrees Farenheit
It is going to be HOT!

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 [17]:
import requests
response = requests.get("https://api.forecast.io/forecast/c9d64e80aa02ca113562a075e57256d7/25.7742700,-80.1936600")
forecast_miami = response.json()
print(forecast_miami.keys())


dict_keys(['offset', 'flags', 'longitude', 'hourly', 'latitude', 'currently', 'timezone', 'daily', 'minutely'])

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']


<class 'dict'>
dict_keys(['data', 'summary', 'icon'])
{'precipIntensity': 0, 'dewPoint': 70.18, 'windSpeed': 6.05, 'humidity': 0.78, 'apparentTemperature': 77.54, 'time': 1466215200, 'cloudCover': 0.09, 'windBearing': 238, 'ozone': 291.94, 'temperature': 77.54, 'summary': 'Clear', 'pressure': 1015.18, 'icon': 'clear-night', 'precipProbability': 0, 'visibility': 9.85}

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")


This is how the weather in Miami will look in the next hours
It will be 77.54 degrees Farenheit
It will be 78.63 degrees Farenheit
It will be 78.68 degrees Farenheit
It will be 78.49 degrees Farenheit
It will be 77.48 degrees Farenheit
It will be 75.98 degrees Farenheit
It will be 76.61 degrees Farenheit
It will be 77.29 degrees Farenheit
It will be 77.96 degrees Farenheit and cloudy!
It will be 78.47 degrees Farenheit and cloudy!
It will be 80.01 degrees Farenheit and cloudy!
It will be 81.94 degrees Farenheit and cloudy!
It will be 84.54 degrees Farenheit and cloudy!
It will be 87.41 degrees Farenheit and cloudy!
It will be 89.79 degrees Farenheit and cloudy!
It will be 91.71 degrees Farenheit and cloudy!
It will be 92.86 degrees Farenheit and cloudy!
It will be 92.01 degrees Farenheit and cloudy!
It will be 91.46 degrees Farenheit and cloudy!
It will be 90.29 degrees Farenheit and cloudy!
It will be 89.46 degrees Farenheit and cloudy!
It will be 87.99 degrees Farenheit and cloudy!
It will be 86.52 degrees Farenheit and cloudy!
It will be 85.25 degrees Farenheit and cloudy!
It will be 85.58 degrees Farenheit and cloudy!
It will be 84.64 degrees Farenheit and cloudy!
It will be 83.5 degrees Farenheit and cloudy!
It will be 82.34 degrees Farenheit and cloudy!
It will be 81.47 degrees Farenheit and cloudy!
It will be 80.97 degrees Farenheit
It will be 80.76 degrees Farenheit
It will be 80.84 degrees Farenheit
It will be 81.04 degrees Farenheit
It will be 81.5 degrees Farenheit and cloudy!
It will be 82.41 degrees Farenheit and cloudy!
It will be 84.14 degrees Farenheit and cloudy!
It will be 86.29 degrees Farenheit
It will be 88.01 degrees Farenheit
It will be 89.01 degrees Farenheit
It will be 89.62 degrees Farenheit and cloudy!
It will be 89.89 degrees Farenheit and cloudy!
It will be 89.01 degrees Farenheit and cloudy!
It will be 87.6 degrees Farenheit and cloudy!
It will be 86.14 degrees Farenheit and cloudy!
It will be 84.73 degrees Farenheit and cloudy!
It will be 83.29 degrees Farenheit and cloudy!
It will be 81.99 degrees Farenheit and cloudy!
It will be 80.69 degrees Farenheit and cloudy!
It will be 79.23 degrees Farenheit and cloudy!

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


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())


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

In [22]:
print(forecast_1980['daily'].keys())


dict_keys(['data'])

In [23]:
print(forecast_1980['daily']['data'])


[{'dewPoint': 20.64, 'sunsetTime': 346592593, 'precipType': 'snow', 'humidity': 0.71, 'sunriseTime': 346559286, 'windSpeed': 0.51, 'apparentTemperatureMaxTime': 346590000, 'time': 346528800, 'cloudCover': 0.36, 'windBearing': 88, 'temperatureMinTime': 346557600, 'apparentTemperatureMin': 14.98, 'temperatureMax': 41.58, 'moonPhase': 0.62, 'temperatureMin': 20.58, 'apparentTemperatureMax': 41.58, 'summary': 'Partly cloudy starting in the afternoon.', 'apparentTemperatureMinTime': 346561200, 'icon': 'partly-cloudy-night', 'temperatureMaxTime': 346590000, 'visibility': 7.91}]

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")


On Christmas Day, 1980, temperatures ranged between 41.58 and 20.58 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())


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

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")


On Christmas Day, 1990, temperatures ranged between 32.27 and 22.41 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())


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

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")


On Christmas Day, 2000, temperatures ranged between 42.25 and 25.05 degrees Farenheit at Central Park

In [ ]:


In [ ]: