Grade = 9.5/10 Make sure to use .lower(). "Right now it is 41.46 degrees out and Drizzle" reads awkwardly.
In [1]:
import requests
In [2]:
response = requests.get("https://api.forecast.io/forecast/c9d64e80aa02ca113562a075e57256d7/40.7128,74.0059")
forecast = response.json()
print(forecast.keys())
In [3]:
forecast['daily'].keys()
Out[3]:
In [4]:
forecast['daily']['data']
Out[4]:
In [5]:
forecast['currently'].keys()
Out[5]:
In [6]:
current_temperature = forecast['currently']['temperature']
In [7]:
print(current_temperature)
In [8]:
current_summary = forecast['currently']['summary']
In [9]:
print(current_summary)
In [10]:
daily_forecast = forecast['daily']['data'][0]
print(daily_forecast)
In [15]:
day_forecast = forecast['daily']['data'][0]['apparentTemperatureMax']
print(day_forecast)
temp_feeling = ""
if day_forecast <= 63:
temp_feeling = 'cold'
if (day_forecast > 63) & (day_forecast<= 75):
temp_feeling = 'moderate'
if (day_forecast> 75) & (day_forecast<= 86):
temp_feeling = 'hot'
if (day_forecast > 86):
temp_feeling = 'extreamly hot'
print(temp_feeling)
In [18]:
high_temp_day_forecast= forecast['daily']['data'][0]['temperatureMax']
#print(high_feeling_day_forecast)
In [12]:
low_temp_day_forecast= forecast['daily']['data'][0]['temperatureMin']
print(low_temp_day_forecast)
In [13]:
rain_forecast= forecast['daily']['data'][0]['precipIntensity']
rain_warning = ""
if rain_forecast <= 0:
rain_warning = ''
if rain_forecast > 0:
rain_warning = 'Expect some rain! Bring your umbrella!'
print(rain_warning)
In [19]:
daily_mail = "Right now it is", current_temperature, "degrees out and", current_summary,". Today will be", temp_feeling, "with a high of", high_temp_day_forecast , "and a low of",low_temp_day_forecast,".", rain_warning
print(' '.join(daily_mail))
In [20]:
mail_text = "Right now it is {} degrees out and {}. Today will be {} with a high of {} and a low of {}.{}".format(current_temperature, current_summary, temp_feeling, high_temp_day_forecast, low_temp_day_forecast, rain_warning)
In [21]:
print(mail_text)
In [ ]:
import time
In [ ]:
time = time.strftime("%B,%d %Y")
In [ ]:
time
In [ ]:
type(time)
In [ ]:
#requests.post(
# "https://api.mailgun.net/v3/sandbox9fe7853d8f49467cb3233031623028cc.mailgun.org/messages",
# auth=("api", ""),
# data={"from": "Mailgun Sandbox <postmaster@sandbox9fe7853d8f49467cb3233031623028cc.mailgun.org>",
# "to": "mercy benzaquen <mercybenzaquen@gmail.com>",
# "subject": "8AM Weather forecast:" + time,
# "text": mail_text })
In [ ]: