<jupyter_start><jupyter_text>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,LONGITUDEA 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!).<jupyter_code>import requests
response = requests.get("https://api.forecast.io/forecast/e554f37a8164ce189acd210d00a452e0/47.4079,9.4647")
weather_data = response.json()
weather_data.keys()
print(weather_data['timezone'])<jupyter_output>Europe/Zurich<jupyter_text>The time zone of Trogen is correct! This is where I live.<jupyter_code>print("Longitude:", weather_data['longitude'], "Latitude", weather_data['latitude'])<jupyter_output>Longitude: 9.4647 Latitude 47.4079<jupyter_text>The longitude is mentioned first, and then the latitude. Usually, it is the other way round. 2) What's the current wind speed? How much warmer does it feel than it actually is?<jupyter_code>type(weather_data['currently'])
weather_data['currently'].keys()
print("The wind in Trogen, Switzerland, is currently blowing at", weather_data['currently']['windSpeed'], "mph.")
weather = weather_data['currently']
Temperature = int(weather['apparentTemperature']) - int(weather['temperature'])
Celsius = round((int(weather['temperature']) - 32) * 5 / 9)
if Temperature == 0:
    print("The temperature feels exactly as you would expect it to feel, namely", weather['temperature'], "degrees Fahrenheit, or", Celsius, "degrees Celsius.")
elif Temperature > 0:
    print("It feels", Temperature, "degrees Fahrenheit warmer than the actual temperature, which is", weather['temperature'], "degrees Fahrenheit, or", Celsius, "degrees Celsius.")
else:
    print("It feels", Temperature, "degrees Fahrenheit colder than the actual temperature, which is", weather['temperature'], "degrees Fahrenheit, or", Celsius, "degrees Celsius.")<jupyter_output>The temperature feels exactly as you would expect it to feel, namely 68.67 degrees Fahrenheit, or 20 degrees Celsius.<jupyter_text>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?<jupyter_code>type(weather_data['daily'])
weather_data['daily'].keys()
type(weather_data['daily']['data'])
for phase in weather_data['daily']['data']:
    moon_forecast_tomorrow = phase['moonPhase']
    break
#print(phase['moonPhase'])
if moon_forecast_tomorrow == 0:
    print("Tomorrow is New Moon.")
elif moon_forecast_tomorrow > .75:
    print("Tomorrow the Moon is in a Waning Crescent phase.")
elif moon_forecast_tomorrow == .75:
    print("Tomorrow is last quarter Moon.")
elif moon_forecast_tomorrow > .5:
    print("Tommorrow the Moon is in a Waning Gibbous phase.")
elif moon_forecast_tomorrow == .5:
    print("Tommorrow is Full Moon.")
elif moon_forecast_tomorrow > .25:
    print("Tommorrow the Moon is a Waxing Gibbous phase.")
elif moon_forecast_tomorrow == .25:
    print("Tommorrow is first Quarter Moon.")
elif moon_forecast_tomorrow > 0:
    print("Tommorrow the Moon is in a Waxing Crescent phase. This is the first phase after New Moon.")<jupyter_output>Tommorrow the Moon is in a Waxing Crescent phase. This is the first phase after New Moon.<jupyter_text>4) What's the difference between the high and low temperatures for today?<jupyter_code>print(weather_data['currently'])
response = requests.get("https://api.forecast.io/forecast/e554f37a8164ce189acd210d00a452e0/47.4079,9.4647,1465420000")
hist_weather_data = response.json()

hist_weather_data.keys()



hist_weather_data['daily'].keys()
print(hist_weather_data['daily']['data'])
for n in hist_weather_data['daily']['data']:
    Min = n['temperatureMin']
    Max = n['temperatureMax']
Min_Max = Max - Min
Min_Max_Celsius = ((Max - 32) * 5 / 9) - ((Min - 32) * 5 / 9)
print("The diffrence between the high and low temperatures on Wedesday, June 8, in Trogen, Switzerland, was", round(Min_Max), "Fahrenheit", "or", round(Min_Max_Celsius), "Celsius.")<jupyter_output>The diffrence between the high and low temperatures on Wedesday, June 8, in Trogen, Switzerland, was 9 Fahrenheit or 5 Celsius.<jupyter_text>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.<jupyter_code>response = requests.get("https://api.forecast.io/forecast/e554f37a8164ce189acd210d00a452e0/40.7128,-74.0059")
weather_data = response.json()
weather_data.keys()
weather_data['daily'].keys()
print(weather_data['daily']['data'][0])
Forecast = weather_data['daily']['data']
for max_temp in Forecast:
    Convert_Celsius = (max_temp['temperatureMax'] - 32) * 5 / 9
    if Convert_Celsius > 30:
        Temperature = "hot"
    elif Convert_Celsius > 20:
        Temperature = "warm"
    else:
        Temperature = "cold"
    print("The maximum temperature in New York for next week are", max_temp['temperatureMax'], "Fahrenheit or", round(Convert_Celsius), "Celsius. That is", Temperature)
 import datetime
print(datetime.datetime.fromtimestamp(int("1284101485")).strftime('%Y-%m-%d'))
import time
import datetime
Forecast = weather_data['daily']['data']
for max_temp in Forecast:
    Convert_Celsius = (max_temp['temperatureMax'] - 32) * 5 / 9
    time1 = max_temp['time']
    if Convert_Celsius > 30:
        Temperature = "hot"
    elif Convert_Celsius > 20:
        Temperature = "comfortably warm."
    else:
        Temperature = "cold"
    #print("On", time.strftime('%A, %b %d', time.localtime(time1)), "the maximum temperature will be", max_temp['temperatureMax'], "Fahrenheit or", round(Convert_Celsius), "Celsius. That is", Temperature)
    print("On", time.strftime('%A', time.localtime(time1)), "the maximum temperature will be", max_temp['temperatureMax'], "Fahrenheit or", round(Convert_Celsius), "Celsius. That is", Temperature)
import datetime
print(datetime.datetime.fromtimestamp(int(time)).strftime('%Y-%m-%d'))<jupyter_output><empty_output><jupyter_text>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.<jupyter_code>response = requests.get("https://api.forecast.io/forecast/e554f37a8164ce189acd210d00a452e0/25.7617,-80.1918")
Florida = response.json()
Florida.keys()
Florida['hourly'].keys()
#print(Florida['hourly']['data'])
import time
import datetime
Hourly = Florida['hourly']['data']
Hourly = Hourly
for weather in Hourly:
    time = weather['time']
    stop_time = datetime.datetime.fromtimestamp(int(time)).strftime('%H')
    if stop_time == '01':
        break
    if weather['cloudCover'] > 0.5:
        cloudy = "and cloudy"
    else:
        cloudy = "not cloudy"
    print(datetime.datetime.fromtimestamp(int(time)).strftime('%H:%M'), "{", weather['temperature'], "°F}",cloudy)<jupyter_output>10:00 { 84.66 °F} and cloudy
11:00 { 86.01 °F} and cloudy
12:00 { 86.45 °F} and cloudy
13:00 { 86.75 °F} and cloudy
14:00 { 87.24 °F} and cloudy
15:00 { 87.18 °F} and cloudy
16:00 { 86.24 °F} and cloudy
17:00 { 85.1 °F} and cloudy
18:00 { 84.04 °F} and cloudy
19:00 { 83.27 °F} and cloudy
20:00 { 82.31 °F} and cloudy
21:00 { 81.45 °F} and cloudy
22:00 { 80.96 °F} and cloudy
23:00 { 80.66 °F} and cloudy
00:00 { 79.94 °F} and cloudy<jupyter_text>7) What was the temperature in Central Park on Christmas Day, 1980? How about 1990? 2000?<jupyter_code>response = requests.get("https://api.forecast.io/forecast/e554f37a8164ce189acd210d00a452e0/40.781750,-73.966641,346593600")
weather_data = response.json()
weather_data.keys()
#print(weather_data['daily']['data'][0])
for Christmas in weather_data['daily']['data']:
    Convert_Celsius = (Christmas['temperatureMax'] - 32) * 5 / 9
    print("The maximum temperature on Christmas Day 1980 in Centralpark was", 
          Christmas['temperatureMax'], "Fahrenheit, or", round(Convert_Celsius), "degrees Celsius.")
response = requests.get("https://api.forecast.io/forecast/e554f37a8164ce189acd210d00a452e0/40.781750,-73.966641,662126400")
weather_data_1990 = response.json()
weather_data_1990.keys()

response = requests.get("https://api.forecast.io/forecast/e554f37a8164ce189acd210d00a452e0/40.781750,-73.966641,977745600")
weather_data_2000 = response.json()
weather_data_2000.keys()
for Christmas in weather_data_1990['daily']['data']:
    Convert_Celsius = (Christmas['temperatureMax'] - 32) * 5 / 9
    print("The maximum temperature on Christmas Day 1990 in Centralpark was", 
          Christmas['temperatureMax'], "Fahrenheit, or", round(Convert_Celsius), "degrees Celsius.")
for Christmas in weather_data_2000['daily']['data']:
    Convert_Celsius = (Christmas['temperatureMax'] - 32) * 5 / 9
    print("The maximum temperature on Christmas Day 1980 in Centralpark was", 
          Christmas['temperatureMax'], "Fahrenheit, or", round(Convert_Celsius), "degrees Celsius.")<jupyter_output>The maximum temperature on Christmas Day 1980 in Centralpark was 27.02 Fahrenheit, or -3 degrees Celsius.
StarcoderdataJupyterStructuredCleanDedup