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(['offset', 'timezone', 'currently', 'latitude', 'longitude', 'flags', 'daily', 'hourly'])

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


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

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


Out[4]:
[{'apparentTemperatureMax': 57.32,
  'apparentTemperatureMaxTime': 1467626400,
  'apparentTemperatureMin': 44.22,
  'apparentTemperatureMinTime': 1467590400,
  'cloudCover': 0.29,
  'dewPoint': 37.57,
  'humidity': 0.6,
  'icon': 'rain',
  'moonPhase': 0.99,
  'ozone': 291.67,
  'precipIntensity': 0.0097,
  'precipIntensityMax': 0.0226,
  'precipIntensityMaxTime': 1467640800,
  'precipProbability': 0.53,
  'precipType': 'rain',
  'pressure': 1007.21,
  'summary': 'Light rain starting in the afternoon.',
  'sunriseTime': 1467589158,
  'sunsetTime': 1467643184,
  'temperatureMax': 57.32,
  'temperatureMaxTime': 1467626400,
  'temperatureMin': 44.22,
  'temperatureMinTime': 1467590400,
  'time': 1467568800,
  'windBearing': 266,
  'windSpeed': 4.78},
 {'apparentTemperatureMax': 55.75,
  'apparentTemperatureMaxTime': 1467705600,
  'apparentTemperatureMin': 43.12,
  'apparentTemperatureMinTime': 1467676800,
  'cloudCover': 0.92,
  'dewPoint': 40.44,
  'humidity': 0.71,
  'icon': 'rain',
  'moonPhase': 0.03,
  'ozone': 295.6,
  'precipIntensity': 0.0148,
  'precipIntensityMax': 0.019,
  'precipIntensityMaxTime': 1467666000,
  'precipProbability': 0.51,
  'precipType': 'rain',
  'pressure': 1008,
  'summary': 'Light rain throughout the day.',
  'sunriseTime': 1467675593,
  'sunsetTime': 1467729569,
  'temperatureMax': 55.75,
  'temperatureMaxTime': 1467705600,
  'temperatureMin': 43.12,
  'temperatureMinTime': 1467676800,
  'time': 1467655200,
  'windBearing': 269,
  'windSpeed': 4.25},
 {'apparentTemperatureMax': 61.15,
  'apparentTemperatureMaxTime': 1467799200,
  'apparentTemperatureMin': 42.3,
  'apparentTemperatureMinTime': 1467763200,
  'cloudCover': 0.81,
  'dewPoint': 37.52,
  'humidity': 0.61,
  'icon': 'rain',
  'moonPhase': 0.07,
  'ozone': 306.71,
  'precipIntensity': 0.003,
  'precipIntensityMax': 0.0063,
  'precipIntensityMaxTime': 1467824400,
  'precipProbability': 0.27,
  'precipType': 'rain',
  'pressure': 1010.71,
  'summary': 'Drizzle starting in the evening.',
  'sunriseTime': 1467762029,
  'sunsetTime': 1467815953,
  'temperatureMax': 61.15,
  'temperatureMaxTime': 1467799200,
  'temperatureMin': 42.3,
  'temperatureMinTime': 1467763200,
  'time': 1467741600,
  'windBearing': 280,
  'windSpeed': 3.95},
 {'apparentTemperatureMax': 60.58,
  'apparentTemperatureMaxTime': 1467885600,
  'apparentTemperatureMin': 43.01,
  'apparentTemperatureMinTime': 1467849600,
  'cloudCover': 0.85,
  'dewPoint': 35.65,
  'humidity': 0.56,
  'icon': 'partly-cloudy-day',
  'moonPhase': 0.1,
  'ozone': 308.33,
  'precipIntensity': 0.0024,
  'precipIntensityMax': 0.0076,
  'precipIntensityMaxTime': 1467835200,
  'precipProbability': 0.35,
  'precipType': 'rain',
  'pressure': 1013.32,
  'summary': 'Mostly cloudy throughout the day.',
  'sunriseTime': 1467848466,
  'sunsetTime': 1467902334,
  'temperatureMax': 60.58,
  'temperatureMaxTime': 1467885600,
  'temperatureMin': 43.01,
  'temperatureMinTime': 1467849600,
  'time': 1467828000,
  'windBearing': 279,
  'windSpeed': 3.53},
 {'apparentTemperatureMax': 62.81,
  'apparentTemperatureMaxTime': 1467972000,
  'apparentTemperatureMin': 37.93,
  'apparentTemperatureMinTime': 1467936000,
  'cloudCover': 0.06,
  'dewPoint': 29.29,
  'humidity': 0.44,
  'icon': 'clear-day',
  'moonPhase': 0.13,
  'ozone': 305.16,
  'precipIntensity': 0,
  'precipIntensityMax': 0,
  'precipProbability': 0,
  'pressure': 1012.42,
  'summary': 'Clear throughout the day.',
  'sunriseTime': 1467934904,
  'sunsetTime': 1467988714,
  'temperatureMax': 62.81,
  'temperatureMaxTime': 1467972000,
  'temperatureMin': 40.86,
  'temperatureMinTime': 1467936000,
  'time': 1467914400,
  'windBearing': 248,
  'windSpeed': 1.09},
 {'apparentTemperatureMax': 63.31,
  'apparentTemperatureMaxTime': 1468058400,
  'apparentTemperatureMin': 42.11,
  'apparentTemperatureMinTime': 1468018800,
  'cloudCover': 0,
  'dewPoint': 26.39,
  'humidity': 0.36,
  'icon': 'clear-day',
  'moonPhase': 0.17,
  'ozone': 294.11,
  'precipIntensity': 0,
  'precipIntensityMax': 0,
  'precipProbability': 0,
  'pressure': 1010.12,
  'summary': 'Clear throughout the day.',
  'sunriseTime': 1468021344,
  'sunsetTime': 1468075091,
  'temperatureMax': 63.31,
  'temperatureMaxTime': 1468058400,
  'temperatureMin': 42.11,
  'temperatureMinTime': 1468018800,
  'time': 1468000800,
  'windBearing': 290,
  'windSpeed': 1.76},
 {'apparentTemperatureMax': 63.84,
  'apparentTemperatureMaxTime': 1468144800,
  'apparentTemperatureMin': 44.13,
  'apparentTemperatureMinTime': 1468108800,
  'cloudCover': 0,
  'dewPoint': 31.98,
  'humidity': 0.44,
  'icon': 'clear-day',
  'moonPhase': 0.2,
  'ozone': 292.32,
  'precipIntensity': 0.0008,
  'precipIntensityMax': 0.0015,
  'precipIntensityMaxTime': 1468152000,
  'precipProbability': 0.03,
  'precipType': 'rain',
  'pressure': 1010.23,
  'summary': 'Clear throughout the day.',
  'sunriseTime': 1468107785,
  'sunsetTime': 1468161467,
  'temperatureMax': 63.84,
  'temperatureMaxTime': 1468144800,
  'temperatureMin': 44.13,
  'temperatureMinTime': 1468108800,
  'time': 1468087200,
  'windBearing': 292,
  'windSpeed': 1.9},
 {'apparentTemperatureMax': 66.22,
  'apparentTemperatureMaxTime': 1468231200,
  'apparentTemperatureMin': 43.48,
  'apparentTemperatureMinTime': 1468191600,
  'cloudCover': 0,
  'dewPoint': 30.81,
  'humidity': 0.4,
  'icon': 'clear-day',
  'moonPhase': 0.23,
  'ozone': 283.52,
  'precipIntensity': 0.0004,
  'precipIntensityMax': 0.0008,
  'precipIntensityMaxTime': 1468238400,
  'precipProbability': 0.01,
  'precipType': 'rain',
  'pressure': 1009.41,
  'summary': 'Clear throughout the day.',
  'sunriseTime': 1468194227,
  'sunsetTime': 1468247841,
  'temperatureMax': 66.22,
  'temperatureMaxTime': 1468231200,
  'temperatureMin': 44.48,
  'temperatureMinTime': 1468195200,
  'time': 1468173600,
  'windBearing': 293,
  'windSpeed': 1.48}]

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


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

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

In [7]:
print(current_temperature)


51.2

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

In [9]:
print(current_summary)


Light Rain

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


{'dewPoint': 37.57, 'time': 1467568800, 'windBearing': 266, 'cloudCover': 0.29, 'windSpeed': 4.78, 'precipType': 'rain', 'sunriseTime': 1467589158, 'precipIntensityMaxTime': 1467640800, 'precipIntensity': 0.0097, 'precipProbability': 0.53, 'sunsetTime': 1467643184, 'moonPhase': 0.99, 'temperatureMaxTime': 1467626400, 'precipIntensityMax': 0.0226, 'apparentTemperatureMaxTime': 1467626400, 'apparentTemperatureMin': 44.22, 'ozone': 291.67, 'icon': 'rain', 'pressure': 1007.21, 'temperatureMinTime': 1467590400, 'summary': 'Light rain starting in the afternoon.', 'temperatureMax': 57.32, 'temperatureMin': 44.22, 'apparentTemperatureMax': 57.32, 'humidity': 0.6, 'apparentTemperatureMinTime': 1467590400}
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 [17]:
high_temp_day_forecast= forecast['daily']['data'][0]['temperatureMax'] 
print(high_feeling_day_forecast)


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-17-251a8c906a59> in <module>()
      1 high_temp_day_forecast= forecast['daily']['data'][0]['temperatureMax']
----> 2 print(high_feeling_day)

NameError: name 'high_feeling_day' is not defined

In [12]:
low_temp_day_forecast= forecast['daily']['data'][0]['temperatureMin'] 
print(low_temp_day_forecast)


44.22

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


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-14-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))

NameError: name 'temp_feeling' is not defined

In [15]:
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)


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-15-b9d8f45e8b26> in <module>()
----> 1 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)

NameError: name 'temp_feeling' is not defined

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