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]:
I have chosen Lima-Peru, the city I was born.
In [5]:
print(weather_Lima['timezone'])
In [6]:
print("Longitude:", weather_Lima['longitude'], "Latitude:", weather_Lima['latitude'])
In [7]:
weather_Lima['currently'].keys()
Out[7]:
In [14]:
Lima_windspeed = weather_Lima['currently']['windSpeed']
print("The wind in Lima is currently blowing at", Lima_windspeed, "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")
In [18]:
weather_Lima['daily'].keys()
Out[18]:
In [19]:
weather_Lima['daily']['data']
Out[19]:
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.")
In [ ]: