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())


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

In [3]:
forecast['daily'].keys()


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

In [4]:
forecast['daily']['data']


Out[4]:
[{'apparentTemperatureMax': 58.32,
  'apparentTemperatureMaxTime': 1467799200,
  'apparentTemperatureMin': 40.09,
  'apparentTemperatureMinTime': 1467770400,
  'cloudCover': 0.69,
  'dewPoint': 34.94,
  'humidity': 0.59,
  'icon': 'rain',
  'moonPhase': 0.07,
  'ozone': 306.53,
  'precipIntensity': 0.0048,
  'precipIntensityMax': 0.0148,
  'precipIntensityMaxTime': 1467741600,
  'precipProbability': 0.49,
  'precipType': 'rain',
  'pressure': 1011.08,
  'summary': 'Light rain until afternoon.',
  'sunriseTime': 1467762029,
  'sunsetTime': 1467815953,
  'temperatureMax': 58.32,
  'temperatureMaxTime': 1467799200,
  'temperatureMin': 41.24,
  'temperatureMinTime': 1467766800,
  'time': 1467741600,
  'windBearing': 260,
  'windSpeed': 4.39},
 {'apparentTemperatureMax': 58.41,
  'apparentTemperatureMaxTime': 1467885600,
  'apparentTemperatureMin': 41.36,
  'apparentTemperatureMinTime': 1467849600,
  'cloudCover': 0.86,
  'dewPoint': 35.07,
  'humidity': 0.58,
  'icon': 'rain',
  'moonPhase': 0.1,
  'ozone': 304.8,
  'precipIntensity': 0.0058,
  'precipIntensityMax': 0.0107,
  'precipIntensityMaxTime': 1467882000,
  'precipProbability': 0.45,
  'precipType': 'rain',
  'pressure': 1013.24,
  'summary': 'Light rain throughout the day.',
  'sunriseTime': 1467848466,
  'sunsetTime': 1467902334,
  'temperatureMax': 58.41,
  'temperatureMaxTime': 1467885600,
  'temperatureMin': 41.36,
  'temperatureMinTime': 1467849600,
  'time': 1467828000,
  'windBearing': 260,
  'windSpeed': 3.71},
 {'apparentTemperatureMax': 63.8,
  'apparentTemperatureMaxTime': 1467975600,
  'apparentTemperatureMin': 39.17,
  'apparentTemperatureMinTime': 1467936000,
  'cloudCover': 0.03,
  'dewPoint': 30.54,
  'humidity': 0.49,
  'icon': 'clear-day',
  'moonPhase': 0.13,
  'ozone': 311.12,
  'precipIntensity': 0.0005,
  'precipIntensityMax': 0.004,
  'precipIntensityMaxTime': 1467914400,
  'precipProbability': 0.14,
  'precipType': 'rain',
  'pressure': 1012.83,
  'summary': 'Clear throughout the day.',
  'sunriseTime': 1467934904,
  'sunsetTime': 1467988714,
  'temperatureMax': 63.8,
  'temperatureMaxTime': 1467975600,
  'temperatureMin': 39.17,
  'temperatureMinTime': 1467936000,
  'time': 1467914400,
  'windBearing': 258,
  'windSpeed': 1.88},
 {'apparentTemperatureMax': 66.77,
  'apparentTemperatureMaxTime': 1468058400,
  'apparentTemperatureMin': 38.65,
  'apparentTemperatureMinTime': 1468018800,
  'cloudCover': 0,
  'dewPoint': 26.26,
  'humidity': 0.35,
  'icon': 'clear-day',
  'moonPhase': 0.17,
  'ozone': 300.9,
  'precipIntensity': 0,
  'precipIntensityMax': 0,
  'precipProbability': 0,
  'pressure': 1010.33,
  'summary': 'Clear throughout the day.',
  'sunriseTime': 1468021344,
  'sunsetTime': 1468075091,
  'temperatureMax': 66.77,
  'temperatureMaxTime': 1468058400,
  'temperatureMin': 41.21,
  'temperatureMinTime': 1468018800,
  'time': 1468000800,
  'windBearing': 287,
  'windSpeed': 1.03},
 {'apparentTemperatureMax': 63.9,
  'apparentTemperatureMaxTime': 1468148400,
  'apparentTemperatureMin': 43.68,
  'apparentTemperatureMinTime': 1468105200,
  'cloudCover': 0,
  'dewPoint': 31.89,
  'humidity': 0.43,
  'icon': 'clear-day',
  'moonPhase': 0.2,
  'ozone': 296.2,
  'precipIntensity': 0,
  'precipIntensityMax': 0,
  'precipProbability': 0,
  'pressure': 1010.55,
  'summary': 'Clear throughout the day.',
  'sunriseTime': 1468107785,
  'sunsetTime': 1468161467,
  'temperatureMax': 63.9,
  'temperatureMaxTime': 1468148400,
  'temperatureMin': 43.68,
  'temperatureMinTime': 1468105200,
  'time': 1468087200,
  'windBearing': 286,
  'windSpeed': 2.33},
 {'apparentTemperatureMax': 66.87,
  'apparentTemperatureMaxTime': 1468231200,
  'apparentTemperatureMin': 42.82,
  'apparentTemperatureMinTime': 1468191600,
  'cloudCover': 0,
  'dewPoint': 31.04,
  'humidity': 0.4,
  'icon': 'clear-day',
  'moonPhase': 0.23,
  'ozone': 288.59,
  'precipIntensity': 0,
  'precipIntensityMax': 0,
  'precipProbability': 0,
  'pressure': 1010.22,
  'summary': 'Clear throughout the day.',
  'sunriseTime': 1468194227,
  'sunsetTime': 1468247841,
  'temperatureMax': 66.87,
  'temperatureMaxTime': 1468231200,
  'temperatureMin': 44.57,
  'temperatureMinTime': 1468191600,
  'time': 1468173600,
  'windBearing': 289,
  'windSpeed': 1.06},
 {'apparentTemperatureMax': 67.63,
  'apparentTemperatureMaxTime': 1468317600,
  'apparentTemperatureMin': 45.62,
  'apparentTemperatureMinTime': 1468278000,
  'cloudCover': 0,
  'dewPoint': 30.73,
  'humidity': 0.38,
  'icon': 'clear-day',
  'moonPhase': 0.26,
  'ozone': 286.07,
  'precipIntensity': 0,
  'precipIntensityMax': 0,
  'precipProbability': 0,
  'pressure': 1009.37,
  'summary': 'Clear throughout the day.',
  'sunriseTime': 1468280671,
  'sunsetTime': 1468334212,
  'temperatureMax': 67.63,
  'temperatureMaxTime': 1468317600,
  'temperatureMin': 45.62,
  'temperatureMinTime': 1468278000,
  'time': 1468260000,
  'windBearing': 280,
  'windSpeed': 1.42},
 {'apparentTemperatureMax': 67.54,
  'apparentTemperatureMaxTime': 1468404000,
  'apparentTemperatureMin': 45.64,
  'apparentTemperatureMinTime': 1468368000,
  'cloudCover': 0,
  'dewPoint': 30.44,
  'humidity': 0.37,
  'icon': 'clear-day',
  'moonPhase': 0.29,
  'ozone': 282.76,
  'precipIntensity': 0,
  'precipIntensityMax': 0,
  'precipProbability': 0,
  'pressure': 1009.28,
  'summary': 'Clear throughout the day.',
  'sunriseTime': 1468367115,
  'sunsetTime': 1468420582,
  'temperatureMax': 67.54,
  'temperatureMaxTime': 1468404000,
  'temperatureMin': 45.64,
  'temperatureMinTime': 1468368000,
  'time': 1468346400,
  'windBearing': 257,
  'windSpeed': 1.64}]

In [5]:
forecast['currently'].keys()


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

In [6]:
current_temperature = forecast['currently']['temperature']

In [7]:
print(current_temperature)


41.46

In [8]:
current_summary = forecast['currently']['summary']

In [9]:
print(current_summary)


Drizzle

In [10]:
daily_forecast = forecast['daily']['data'][0]
print(daily_forecast)


{'apparentTemperatureMaxTime': 1467799200, 'cloudCover': 0.69, 'precipIntensityMaxTime': 1467741600, 'sunriseTime': 1467762029, 'time': 1467741600, 'pressure': 1011.08, 'dewPoint': 34.94, 'ozone': 306.53, 'sunsetTime': 1467815953, 'temperatureMax': 58.32, 'apparentTemperatureMinTime': 1467770400, 'apparentTemperatureMax': 58.32, 'moonPhase': 0.07, 'windSpeed': 4.39, 'precipIntensity': 0.0048, 'precipIntensityMax': 0.0148, 'temperatureMinTime': 1467766800, 'summary': 'Light rain until afternoon.', 'icon': 'rain', 'precipProbability': 0.49, 'apparentTemperatureMin': 40.09, 'humidity': 0.59, 'temperatureMaxTime': 1467799200, 'windBearing': 260, 'temperatureMin': 41.24, 'precipType': 'rain'}

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)


58.32
cold

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)


41.24

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)


Expect some rain! Bring your umbrella!

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))


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-19-deb5d0c2c0b8> in <module>()
      1 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
----> 2 print(' '.join(daily_mail))

TypeError: sequence item 1: expected str instance, float found

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)


Right now it is 41.46 degrees out and Drizzle. Today will be cold with a high of 58.32 and a low of 41.24.Expect some rain! Bring your umbrella!

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 [ ]: