You'll be using the Dark Sky Forecast API from Forecast.io, available at https://developer.forecast.io. It's a pretty simple API, but be sure to read the documentation!

A forecast request returns the current forecast (for the next week): https://api.forecast.io/forecast/APIKEY/LATITUDE,LONGITUDE A time-machine request returns the observed weather at a given time (for many places, up to 60 years in the past): https://api.forecast.io/forecast/APIKEY/LATITUDE,LONGITUDE,TIME 1) Make a request from the Forecast.io API for where you were born (or lived, or want to visit!).


In [1]:
import requests

In [2]:
response = requests.get("https://api.forecast.io/forecast/5afc9217d7eea82824254c951b1b57f4/-12.0561,-77.0268")

In [3]:
weather_Lima = response.json()
weather_Lima.keys()


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

I have chosen Lima-Peru, the city I was born.


In [4]:
print(weather_Lima['timezone'])


America/Lima

In [5]:
print("Longitude:", weather_Lima['longitude'], "Latitude:", weather_Lima['latitude'])


Longitude: -77.0268 Latitude: -12.0561

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


In [6]:
weather_Lima['currently'].keys()


Out[6]:
dict_keys(['windBearing', 'precipIntensity', 'temperature', 'windSpeed', 'summary', 'pressure', 'humidity', 'time', 'cloudCover', 'ozone', 'icon', 'precipProbability', 'apparentTemperature', 'dewPoint'])

In [7]:
Lima_windspeed = weather_Lima['currently']['windSpeed']
print("The wind in Lima is currently blowing at", Lima_windspeed, "mph")


The wind in Lima is currently blowing at 8.5 mph

In [8]:
weather = weather_Lima['currently']
Temperature = int(weather['apparentTemperature']) - int(weather['temperature'])
if Temperature == 0:
    print("The temperature feels exactly as expected:", weather['temperature'], "degrees Fahrenheit")
elif Temperature > 0:
    print("It feels", Temperature, "degrees Fahrenheit warmer than the actual temperature:", weather['temperature'], "degrees Fahrenheit")
else:
    print("It feels", Temperature, "degrees Fahrenheit colder than the actual temperature:", weather['temperature'], "degrees Fahrenheit")


The temperature feels exactly as expected: 63.78 degrees Fahrenheit

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 [9]:
weather_Lima['daily'].keys()


Out[9]:
dict_keys(['data', 'summary', 'icon'])

In [10]:
weather_Lima['daily']['data']


Out[10]:
[{'apparentTemperatureMax': 67.24,
  'apparentTemperatureMaxTime': 1466964000,
  'apparentTemperatureMin': 54.37,
  'apparentTemperatureMinTime': 1466928000,
  'cloudCover': 0.11,
  'dewPoint': 52.53,
  'humidity': 0.76,
  'icon': 'clear-day',
  'moonPhase': 0.71,
  'ozone': 249.47,
  'precipIntensity': 0,
  'precipIntensityMax': 0,
  'precipProbability': 0,
  'pressure': 1014.8,
  'summary': 'Clear throughout the day.',
  'sunriseTime': 1466940581,
  'sunsetTime': 1466981690,
  'temperatureMax': 67.24,
  'temperatureMaxTime': 1466964000,
  'temperatureMin': 54.37,
  'temperatureMinTime': 1466928000,
  'time': 1466917200,
  'windBearing': 178,
  'windSpeed': 7.07},
 {'apparentTemperatureMax': 72.03,
  'apparentTemperatureMaxTime': 1467050400,
  'apparentTemperatureMin': 56.44,
  'apparentTemperatureMinTime': 1467025200,
  'cloudCover': 0.11,
  'dewPoint': 54.31,
  'humidity': 0.75,
  'icon': 'clear-day',
  'moonPhase': 0.75,
  'ozone': 247.33,
  'precipIntensity': 0,
  'precipIntensityMax': 0,
  'precipProbability': 0,
  'pressure': 1014.19,
  'summary': 'Clear throughout the day.',
  'sunriseTime': 1467026990,
  'sunsetTime': 1467068104,
  'temperatureMax': 72.03,
  'temperatureMaxTime': 1467050400,
  'temperatureMin': 56.44,
  'temperatureMinTime': 1467025200,
  'time': 1467003600,
  'windBearing': 174,
  'windSpeed': 7.74},
 {'apparentTemperatureMax': 71.16,
  'apparentTemperatureMaxTime': 1467136800,
  'apparentTemperatureMin': 56.71,
  'apparentTemperatureMinTime': 1467108000,
  'cloudCover': 0.13,
  'dewPoint': 55.01,
  'humidity': 0.78,
  'icon': 'clear-day',
  'moonPhase': 0.79,
  'ozone': 244.46,
  'precipIntensity': 0,
  'precipIntensityMax': 0,
  'precipProbability': 0,
  'pressure': 1014.55,
  'summary': 'Clear throughout the day.',
  'sunriseTime': 1467113399,
  'sunsetTime': 1467154518,
  'temperatureMax': 71.16,
  'temperatureMaxTime': 1467136800,
  'temperatureMin': 56.71,
  'temperatureMinTime': 1467108000,
  'time': 1467090000,
  'windBearing': 183,
  'windSpeed': 5.78},
 {'apparentTemperatureMax': 72.42,
  'apparentTemperatureMaxTime': 1467223200,
  'apparentTemperatureMin': 55.53,
  'apparentTemperatureMinTime': 1467194400,
  'cloudCover': 0.04,
  'dewPoint': 54.7,
  'humidity': 0.77,
  'icon': 'clear-day',
  'moonPhase': 0.83,
  'ozone': 240.97,
  'precipIntensity': 0,
  'precipIntensityMax': 0,
  'precipProbability': 0,
  'pressure': 1014.93,
  'summary': 'Clear throughout the day.',
  'sunriseTime': 1467199807,
  'sunsetTime': 1467240933,
  'temperatureMax': 72.42,
  'temperatureMaxTime': 1467223200,
  'temperatureMin': 55.53,
  'temperatureMinTime': 1467194400,
  'time': 1467176400,
  'windBearing': 181,
  'windSpeed': 5.46},
 {'apparentTemperatureMax': 70.02,
  'apparentTemperatureMaxTime': 1467309600,
  'apparentTemperatureMin': 56.59,
  'apparentTemperatureMinTime': 1467280800,
  'cloudCover': 0.08,
  'dewPoint': 54.27,
  'humidity': 0.77,
  'icon': 'clear-day',
  'moonPhase': 0.86,
  'ozone': 238.8,
  'precipIntensity': 0,
  'precipIntensityMax': 0,
  'precipProbability': 0,
  'pressure': 1015.16,
  'summary': 'Clear throughout the day.',
  'sunriseTime': 1467286214,
  'sunsetTime': 1467327348,
  'temperatureMax': 70.02,
  'temperatureMaxTime': 1467309600,
  'temperatureMin': 56.59,
  'temperatureMinTime': 1467280800,
  'time': 1467262800,
  'windBearing': 181,
  'windSpeed': 5.92},
 {'apparentTemperatureMax': 68.11,
  'apparentTemperatureMaxTime': 1467399600,
  'apparentTemperatureMin': 56.36,
  'apparentTemperatureMinTime': 1467370800,
  'cloudCover': 0.26,
  'dewPoint': 54.3,
  'humidity': 0.79,
  'icon': 'partly-cloudy-night',
  'moonPhase': 0.9,
  'ozone': 238.52,
  'precipIntensity': 0,
  'precipIntensityMax': 0,
  'precipProbability': 0,
  'pressure': 1016.08,
  'summary': 'Partly cloudy throughout the day.',
  'sunriseTime': 1467372621,
  'sunsetTime': 1467413763,
  'temperatureMax': 68.11,
  'temperatureMaxTime': 1467399600,
  'temperatureMin': 56.36,
  'temperatureMinTime': 1467370800,
  'time': 1467349200,
  'windBearing': 181,
  'windSpeed': 5.53},
 {'apparentTemperatureMax': 69.44,
  'apparentTemperatureMaxTime': 1467482400,
  'apparentTemperatureMin': 56.12,
  'apparentTemperatureMinTime': 1467450000,
  'cloudCover': 0.6,
  'dewPoint': 53.93,
  'humidity': 0.77,
  'icon': 'partly-cloudy-day',
  'moonPhase': 0.94,
  'ozone': 242.32,
  'precipIntensity': 0,
  'precipIntensityMax': 0,
  'precipProbability': 0,
  'pressure': 1016.65,
  'summary': 'Mostly cloudy throughout the day.',
  'sunriseTime': 1467459027,
  'sunsetTime': 1467500178,
  'temperatureMax': 69.44,
  'temperatureMaxTime': 1467482400,
  'temperatureMin': 56.12,
  'temperatureMinTime': 1467450000,
  'time': 1467435600,
  'windBearing': 177,
  'windSpeed': 5.62},
 {'apparentTemperatureMax': 69.06,
  'apparentTemperatureMaxTime': 1467568800,
  'apparentTemperatureMin': 55.28,
  'apparentTemperatureMinTime': 1467543600,
  'cloudCover': 0.55,
  'dewPoint': 53.57,
  'humidity': 0.79,
  'icon': 'partly-cloudy-day',
  'moonPhase': 0.97,
  'ozone': 245.26,
  'precipIntensity': 0,
  'precipIntensityMax': 0,
  'precipProbability': 0,
  'pressure': 1017.15,
  'summary': 'Partly cloudy throughout the day.',
  'sunriseTime': 1467545433,
  'sunsetTime': 1467586593,
  'temperatureMax': 69.06,
  'temperatureMaxTime': 1467568800,
  'temperatureMin': 55.28,
  'temperatureMinTime': 1467543600,
  'time': 1467522000,
  'windBearing': 175,
  'windSpeed': 5.66}]

In [11]:
for moon in weather_Lima['daily']['data']:
    moon_forecast = moon['moonPhase']
    break
if moon_forecast == 0:
    print("Tomorrow is New Moon.")
elif moon_forecast > .75:
    print("Tomorrow the Moon is in a Waning Crescent phase.")
elif moon_forecast == .75:
    print("Tomorrow is last quarter Moon.")
elif moon_forecast > .5:
    print("Tommorrow the Moon is in a Waning Gibbous phase.")
elif moon_forecast == .5:
    print("Tommorrow is Full Moon.")
elif moon_forecast > .25:
    print("Tommorrow the Moon is a Waxing Gibbous phase.")
elif moon_forecast == .25:
    print("Tommorrow is first Quarter Moon.")
elif moon_forecast > 0:
        print("Tommorrow the Moon is in a Waxing Crescent phase. This is the first phase after New Moon.")


Tommorrow the Moon is in a Waning Gibbous phase.

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


In [13]:
print(weather_Lima['currently'])


{'windBearing': 183, 'precipIntensity': 0, 'temperature': 63.78, 'windSpeed': 8.5, 'summary': 'Clear', 'pressure': 1013.3, 'humidity': 0.7, 'time': 1466977579, 'cloudCover': 0.08, 'ozone': 247.64, 'icon': 'clear-day', 'precipProbability': 0, 'apparentTemperature': 63.78, 'dewPoint': 53.95}

In [42]:
response = requests.get("https://api.forecast.io/forecast/5afc9217d7eea82824254c951b1b57f4/-12.0561,-77.0268")
hist_weather_Lima = response.json()
hist_weather_Lima.keys()


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

In [43]:
hist_weather_Lima['daily'].keys()


Out[43]:
dict_keys(['data', 'summary', 'icon'])

In [54]:
today_lim = hist_weather_Lima['daily']['data']

In [60]:
maxi = today_lim[0]['temperatureMax']
mini = today_lim[0]['temperatureMin']

In [62]:
Min_Max = maxi - mini
print("The diffrence between the highist and lowest temp. for today in Lima, Peru, was", round(Min_Max), "Fahrenheit")


The diffrence between the highist and lowest temp. for today in Lima, Peru, was 13 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 [47]:
response = requests.get("https://api.forecast.io/forecast/5afc9217d7eea82824254c951b1b57f4/-12.0561,-77.0268")
daily_weather_Lima = response.json()
daily_weather_Lima.keys()


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

In [75]:
week_report = daily_weather_Lima['daily']['data'][1:] #For the following 7 days

In [74]:
for day in week_report:
    Celsius = (day['temperatureMax'] - 32) * 5 / 9
    if Celsius > 28:
        Temperature = "hot"
    elif Celsius > 18:
        Temperature = "warm"
    else:
        Temperature = "cold"
    print("The maximum temperature in Lima for this day is", round(Celsius), "degrees. This is", Temperature)


The maximum temperature in Lima for this day is 22 degrees. This is warm
The maximum temperature in Lima for this day is 22 degrees. This is warm
The maximum temperature in Lima for this day is 22 degrees. This is warm
The maximum temperature in Lima for this day is 21 degrees. This is warm
The maximum temperature in Lima for this day is 20 degrees. This is warm
The maximum temperature in Lima for this day is 21 degrees. This is warm
The maximum temperature in Lima for this day is 21 degrees. This 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 [76]:
response = requests.get("https://api.forecast.io/forecast/e554f37a8164ce189acd210d00a452e0/25.7617,-80.1918")
Florida = response.json()
Florida.keys()


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

In [ ]: