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 [4]:
weather_Lima = response.json()
weather_Lima.keys()


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

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


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


America/Lima

In [6]:
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 [7]:
weather_Lima['currently'].keys()


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

In [14]:
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 7.76 mph

In [17]:
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: 58.27 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 [18]:
weather_Lima['daily'].keys()


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

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


Out[19]:
[{'apparentTemperatureMax': 65.66,
  'apparentTemperatureMaxTime': 1466359200,
  'apparentTemperatureMin': 56.2,
  'apparentTemperatureMinTime': 1466326800,
  'cloudCover': 0.17,
  'dewPoint': 54.37,
  'humidity': 0.82,
  'icon': 'clear-day',
  'moonPhase': 0.47,
  'ozone': 247.78,
  'precipIntensity': 0,
  'precipIntensityMax': 0,
  'precipProbability': 0,
  'pressure': 1015.91,
  'summary': 'Clear throughout the day.',
  'sunriseTime': 1466335702,
  'sunsetTime': 1466376800,
  'temperatureMax': 65.66,
  'temperatureMaxTime': 1466359200,
  'temperatureMin': 56.2,
  'temperatureMinTime': 1466326800,
  'time': 1466312400,
  'windBearing': 180,
  'windSpeed': 7.28},
 {'apparentTemperatureMax': 70.96,
  'apparentTemperatureMaxTime': 1466445600,
  'apparentTemperatureMin': 56.34,
  'apparentTemperatureMinTime': 1466413200,
  'cloudCover': 0.13,
  'dewPoint': 54.89,
  'humidity': 0.79,
  'icon': 'clear-day',
  'moonPhase': 0.51,
  'ozone': 247.83,
  'precipIntensity': 0,
  'precipIntensityMax': 0,
  'precipProbability': 0,
  'pressure': 1015.17,
  'summary': 'Clear throughout the day.',
  'sunriseTime': 1466422115,
  'sunsetTime': 1466463212,
  'temperatureMax': 70.96,
  'temperatureMaxTime': 1466445600,
  'temperatureMin': 56.34,
  'temperatureMinTime': 1466413200,
  'time': 1466398800,
  'windBearing': 174,
  'windSpeed': 8.05},
 {'apparentTemperatureMax': 70.93,
  'apparentTemperatureMaxTime': 1466532000,
  'apparentTemperatureMin': 56.86,
  'apparentTemperatureMinTime': 1466503200,
  'cloudCover': 0.36,
  'dewPoint': 54.76,
  'humidity': 0.78,
  'icon': 'partly-cloudy-day',
  'moonPhase': 0.54,
  'ozone': 248.09,
  'precipIntensity': 0,
  'precipIntensityMax': 0,
  'precipProbability': 0,
  'pressure': 1014.88,
  'summary': 'Partly cloudy throughout the day.',
  'sunriseTime': 1466508527,
  'sunsetTime': 1466549624,
  'temperatureMax': 70.93,
  'temperatureMaxTime': 1466532000,
  'temperatureMin': 56.86,
  'temperatureMinTime': 1466503200,
  'time': 1466485200,
  'windBearing': 177,
  'windSpeed': 6.87},
 {'apparentTemperatureMax': 70.78,
  'apparentTemperatureMaxTime': 1466618400,
  'apparentTemperatureMin': 56.79,
  'apparentTemperatureMinTime': 1466586000,
  'cloudCover': 0.47,
  'dewPoint': 54.8,
  'humidity': 0.79,
  'icon': 'partly-cloudy-day',
  'moonPhase': 0.57,
  'ozone': 246.39,
  'precipIntensity': 0,
  'precipIntensityMax': 0,
  'precipProbability': 0,
  'pressure': 1015.27,
  'summary': 'Partly cloudy throughout the day.',
  'sunriseTime': 1466594939,
  'sunsetTime': 1466636037,
  'temperatureMax': 70.78,
  'temperatureMaxTime': 1466618400,
  'temperatureMin': 56.79,
  'temperatureMinTime': 1466586000,
  'time': 1466571600,
  'windBearing': 177,
  'windSpeed': 6.6},
 {'apparentTemperatureMax': 70.79,
  'apparentTemperatureMaxTime': 1466704800,
  'apparentTemperatureMin': 56.7,
  'apparentTemperatureMinTime': 1466668800,
  'cloudCover': 0.4,
  'dewPoint': 53.91,
  'humidity': 0.76,
  'icon': 'partly-cloudy-day',
  'moonPhase': 0.61,
  'ozone': 243.35,
  'precipIntensity': 0,
  'precipIntensityMax': 0,
  'precipProbability': 0,
  'pressure': 1015.79,
  'summary': 'Partly cloudy until evening.',
  'sunriseTime': 1466681350,
  'sunsetTime': 1466722450,
  'temperatureMax': 70.79,
  'temperatureMaxTime': 1466704800,
  'temperatureMin': 56.7,
  'temperatureMinTime': 1466668800,
  'time': 1466658000,
  'windBearing': 174,
  'windSpeed': 6.05},
 {'apparentTemperatureMax': 69.49,
  'apparentTemperatureMaxTime': 1466791200,
  'apparentTemperatureMin': 56.76,
  'apparentTemperatureMinTime': 1466762400,
  'cloudCover': 0.19,
  'dewPoint': 53.13,
  'humidity': 0.75,
  'icon': 'partly-cloudy-night',
  'moonPhase': 0.64,
  'ozone': 245.66,
  'precipIntensity': 0,
  'precipIntensityMax': 0,
  'precipProbability': 0,
  'pressure': 1015.13,
  'summary': 'Partly cloudy overnight.',
  'sunriseTime': 1466767761,
  'sunsetTime': 1466808863,
  'temperatureMax': 69.49,
  'temperatureMaxTime': 1466791200,
  'temperatureMin': 56.76,
  'temperatureMinTime': 1466762400,
  'time': 1466744400,
  'windBearing': 180,
  'windSpeed': 5.99},
 {'apparentTemperatureMax': 68.49,
  'apparentTemperatureMaxTime': 1466874000,
  'apparentTemperatureMin': 56.81,
  'apparentTemperatureMinTime': 1466845200,
  'cloudCover': 0.51,
  'dewPoint': 52.82,
  'humidity': 0.75,
  'icon': 'partly-cloudy-day',
  'moonPhase': 0.68,
  'ozone': 247.62,
  'precipIntensity': 0,
  'precipIntensityMax': 0,
  'precipProbability': 0,
  'pressure': 1013.85,
  'summary': 'Partly cloudy throughout the day.',
  'sunriseTime': 1466854171,
  'sunsetTime': 1466895276,
  'temperatureMax': 68.49,
  'temperatureMaxTime': 1466874000,
  'temperatureMin': 56.81,
  'temperatureMinTime': 1466845200,
  'time': 1466830800,
  'windBearing': 184,
  'windSpeed': 5.38},
 {'apparentTemperatureMax': 67.19,
  'apparentTemperatureMaxTime': 1466960400,
  'apparentTemperatureMin': 54.86,
  'apparentTemperatureMinTime': 1466931600,
  'cloudCover': 0.74,
  'dewPoint': 52.47,
  'humidity': 0.75,
  'icon': 'partly-cloudy-day',
  'moonPhase': 0.71,
  'ozone': 247.95,
  'precipIntensity': 0,
  'precipIntensityMax': 0,
  'precipProbability': 0,
  'pressure': 1014.86,
  'summary': 'Mostly cloudy throughout the day.',
  'sunriseTime': 1466940581,
  'sunsetTime': 1466981690,
  'temperatureMax': 67.19,
  'temperatureMaxTime': 1466960400,
  'temperatureMin': 54.86,
  'temperatureMinTime': 1466931600,
  'time': 1466917200,
  'windBearing': 192,
  'windSpeed': 4.11}]

In [28]:
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 a Waxing Gibbous phase.

In [ ]: