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]:
I have chosen Lima-Peru, the city I was born.
In [4]:
    
print(weather_Lima['timezone'])
    
    
In [5]:
    
print("Longitude:", weather_Lima['longitude'], "Latitude:", weather_Lima['latitude'])
    
    
In [6]:
    
weather_Lima['currently'].keys()
    
    Out[6]:
In [7]:
    
Lima_windspeed = weather_Lima['currently']['windSpeed']
print("The wind in Lima is currently blowing at", Lima_windspeed, "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")
    
    
In [9]:
    
weather_Lima['daily'].keys()
    
    Out[9]:
In [10]:
    
weather_Lima['daily']['data']
    
    Out[10]:
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.")
    
    
In [13]:
    
print(weather_Lima['currently'])
    
    
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]:
In [43]:
    
hist_weather_Lima['daily'].keys()
    
    Out[43]:
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")
    
    
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]:
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)
    
    
In [76]:
    
response = requests.get("https://api.forecast.io/forecast/e554f37a8164ce189acd210d00a452e0/25.7617,-80.1918")
Florida = response.json()
Florida.keys()
    
    Out[76]:
In [ ]: