Grade: 10 / 10 -- this looks great!


In [8]:
import requests

In [9]:
!pip install requests


Requirement already satisfied (use --upgrade to upgrade): requests in /Users/skkandrach/.virtualenvs/lede/lib/python3.5/site-packages

In [10]:
response = requests.get("https://api.forecast.io/forecast/c9d64e80aa02ca113562a075e57256d7/40.7128,74.0059")
forecast = response.json()
print(forecast.keys())


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

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


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

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


Out[12]:
[{'apparentTemperatureMax': 68.26,
  'apparentTemperatureMaxTime': 1467194400,
  'apparentTemperatureMin': 42.22,
  'apparentTemperatureMinTime': 1467158400,
  'cloudCover': 0.07,
  'dewPoint': 35.02,
  'humidity': 0.49,
  'icon': 'clear-day',
  'moonPhase': 0.81,
  'ozone': 295.42,
  'precipIntensity': 0,
  'precipIntensityMax': 0,
  'precipProbability': 0,
  'pressure': 1012.95,
  'summary': 'Clear throughout the day.',
  'sunriseTime': 1467157009,
  'sunsetTime': 1467211226,
  'temperatureMax': 68.26,
  'temperatureMaxTime': 1467194400,
  'temperatureMin': 42.22,
  'temperatureMinTime': 1467158400,
  'time': 1467136800,
  'windBearing': 277,
  'windSpeed': 2.19},
 {'apparentTemperatureMax': 69.63,
  'apparentTemperatureMaxTime': 1467280800,
  'apparentTemperatureMin': 42.92,
  'apparentTemperatureMinTime': 1467241200,
  'cloudCover': 0,
  'dewPoint': 33.79,
  'humidity': 0.44,
  'icon': 'clear-day',
  'moonPhase': 0.85,
  'ozone': 291.31,
  'precipIntensity': 0,
  'precipIntensityMax': 0,
  'precipProbability': 0,
  'pressure': 1011.36,
  'summary': 'Clear throughout the day.',
  'sunriseTime': 1467243436,
  'sunsetTime': 1467297622,
  'temperatureMax': 69.63,
  'temperatureMaxTime': 1467280800,
  'temperatureMin': 42.92,
  'temperatureMinTime': 1467241200,
  'time': 1467223200,
  'windBearing': 269,
  'windSpeed': 3.08},
 {'apparentTemperatureMax': 67.59,
  'apparentTemperatureMaxTime': 1467367200,
  'apparentTemperatureMin': 45.39,
  'apparentTemperatureMinTime': 1467327600,
  'cloudCover': 0,
  'dewPoint': 36.76,
  'humidity': 0.49,
  'icon': 'clear-day',
  'moonPhase': 0.88,
  'ozone': 292.41,
  'precipIntensity': 0.0005,
  'precipIntensityMax': 0.0011,
  'precipIntensityMaxTime': 1467374400,
  'precipProbability': 0.02,
  'precipType': 'rain',
  'pressure': 1008.9,
  'summary': 'Clear throughout the day.',
  'sunriseTime': 1467329864,
  'sunsetTime': 1467384015,
  'temperatureMax': 67.59,
  'temperatureMaxTime': 1467367200,
  'temperatureMin': 45.39,
  'temperatureMinTime': 1467327600,
  'time': 1467309600,
  'windBearing': 289,
  'windSpeed': 3.56},
 {'apparentTemperatureMax': 67.61,
  'apparentTemperatureMaxTime': 1467457200,
  'apparentTemperatureMin': 45.35,
  'apparentTemperatureMinTime': 1467417600,
  'cloudCover': 0.01,
  'dewPoint': 35.52,
  'humidity': 0.46,
  'icon': 'clear-day',
  'moonPhase': 0.92,
  'ozone': 287.36,
  'precipIntensity': 0,
  'precipIntensityMax': 0,
  'precipProbability': 0,
  'pressure': 1006.48,
  'summary': 'Clear throughout the day.',
  'sunriseTime': 1467416294,
  'sunsetTime': 1467470407,
  'temperatureMax': 67.61,
  'temperatureMaxTime': 1467457200,
  'temperatureMin': 45.35,
  'temperatureMinTime': 1467417600,
  'time': 1467396000,
  'windBearing': 289,
  'windSpeed': 3.04},
 {'apparentTemperatureMax': 64.76,
  'apparentTemperatureMaxTime': 1467540000,
  'apparentTemperatureMin': 45.94,
  'apparentTemperatureMinTime': 1467504000,
  'cloudCover': 0.14,
  'dewPoint': 35.46,
  'humidity': 0.47,
  'icon': 'partly-cloudy-night',
  'moonPhase': 0.96,
  'ozone': 293.39,
  'precipIntensity': 0,
  'precipIntensityMax': 0,
  'precipProbability': 0,
  'pressure': 1006.25,
  'summary': 'Mostly cloudy starting in the evening.',
  'sunriseTime': 1467502726,
  'sunsetTime': 1467556796,
  'temperatureMax': 64.76,
  'temperatureMaxTime': 1467540000,
  'temperatureMin': 45.94,
  'temperatureMinTime': 1467504000,
  'time': 1467482400,
  'windBearing': 298,
  'windSpeed': 4.26},
 {'apparentTemperatureMax': 62.37,
  'apparentTemperatureMaxTime': 1467626400,
  'apparentTemperatureMin': 46.1,
  'apparentTemperatureMinTime': 1467590400,
  'cloudCover': 0.26,
  'dewPoint': 35.93,
  'humidity': 0.5,
  'icon': 'partly-cloudy-day',
  'moonPhase': 0.99,
  'ozone': 297.3,
  'precipIntensity': 0.0008,
  'precipIntensityMax': 0.001,
  'precipIntensityMaxTime': 1467648000,
  'precipProbability': 0.01,
  'precipType': 'rain',
  'pressure': 1006.08,
  'summary': 'Partly cloudy starting in the evening.',
  'sunriseTime': 1467589158,
  'sunsetTime': 1467643184,
  'temperatureMax': 62.37,
  'temperatureMaxTime': 1467626400,
  'temperatureMin': 46.1,
  'temperatureMinTime': 1467590400,
  'time': 1467568800,
  'windBearing': 305,
  'windSpeed': 4.08},
 {'apparentTemperatureMax': 60.36,
  'apparentTemperatureMaxTime': 1467709200,
  'apparentTemperatureMin': 44.42,
  'apparentTemperatureMinTime': 1467676800,
  'cloudCover': 0.38,
  'dewPoint': 35.38,
  'humidity': 0.53,
  'icon': 'partly-cloudy-day',
  'moonPhase': 0.03,
  'ozone': 303.73,
  'precipIntensity': 0.0014,
  'precipIntensityMax': 0.0032,
  'precipIntensityMaxTime': 1467734400,
  'precipProbability': 0.11,
  'precipType': 'rain',
  'pressure': 1006.24,
  'summary': 'Mostly cloudy starting in the afternoon.',
  'sunriseTime': 1467675593,
  'sunsetTime': 1467729569,
  'temperatureMax': 60.36,
  'temperatureMaxTime': 1467709200,
  'temperatureMin': 44.42,
  'temperatureMinTime': 1467676800,
  'time': 1467655200,
  'windBearing': 304,
  'windSpeed': 3.58},
 {'apparentTemperatureMax': 61.86,
  'apparentTemperatureMaxTime': 1467795600,
  'apparentTemperatureMin': 43.39,
  'apparentTemperatureMinTime': 1467763200,
  'cloudCover': 0.54,
  'dewPoint': 35.88,
  'humidity': 0.53,
  'icon': 'partly-cloudy-day',
  'moonPhase': 0.07,
  'ozone': 303.09,
  'precipIntensity': 0.0015,
  'precipIntensityMax': 0.0046,
  'precipIntensityMaxTime': 1467824400,
  'precipProbability': 0.18,
  'precipType': 'rain',
  'pressure': 1007.25,
  'summary': 'Partly cloudy throughout the day.',
  'sunriseTime': 1467762029,
  'sunsetTime': 1467815953,
  'temperatureMax': 61.86,
  'temperatureMaxTime': 1467795600,
  'temperatureMin': 43.39,
  'temperatureMinTime': 1467763200,
  'time': 1467741600,
  'windBearing': 307,
  'windSpeed': 3.29}]

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


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

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

In [15]:
print(current_temperature)


47.84

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

In [17]:
print(current_summary)


Partly Cloudy

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


{'time': 1467136800, 'temperatureMaxTime': 1467194400, 'sunsetTime': 1467211226, 'pressure': 1012.95, 'temperatureMax': 68.26, 'temperatureMin': 42.22, 'windBearing': 277, 'apparentTemperatureMaxTime': 1467194400, 'dewPoint': 35.02, 'apparentTemperatureMin': 42.22, 'humidity': 0.49, 'apparentTemperatureMinTime': 1467158400, 'ozone': 295.42, 'precipIntensityMax': 0, 'precipIntensity': 0, 'summary': 'Clear throughout the day.', 'apparentTemperatureMax': 68.26, 'sunriseTime': 1467157009, 'moonPhase': 0.81, 'windSpeed': 2.19, 'temperatureMinTime': 1467158400, 'cloudCover': 0.07, 'icon': 'clear-day', 'precipProbability': 0}

In [48]:
def temp_feeling(t):
    data = t['daily']['data']
    for item in data:
        temp_feeling = item['temperatureMin']
        if temp_feeling < 60:
            return "cold"
        elif temp_feeling > 60:
            return "moderate"
        elif temp_feeling < 75:
            return "warm"
        elif temp_feeling > 75:
            return "hot"

In [49]:
high_temp_forecast= forecast['daily']['data'][0]['temperatureMax'] 
print(high_temp_forecast)


68.26

In [50]:
low_temp_forecast= forecast['daily']['data'][0]['temperatureMin'] 
print(low_temp_forecast)


42.22

In [51]:
rain_forecast= forecast['daily']['data'][0]['precipIntensity']
rain_warning = ""
if rain_forecast <= 0:
    rain_warning = ''
if rain_forecast > 0:
    rain_warning = 'Prepare for some precipitation...Bring your umbrella!'
print(rain_warning)




In [52]:
daily_mail = "Right now it is", current_temperature, "degrees out and", current_summary,"Today will be", temp_feeling, "with a high of", high_temp_forecast , "and a low of",
low_temp_forecast,".", rain_warning
print(' '.join(daily_mail))


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-52-bf47ecfca4c9> 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_forecast , "and a low of",
      2 low_temp_forecast,".", rain_warning
----> 3 print(' '.join(daily_mail))

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

In [53]:
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_forecast, low_temp_forecast, rain_warning)
print(mail_text)


Right now it is 47.84 degrees out and Partly Cloudy. Today will be <function temp_feeling at 0x110d23620> with a high of 68.26 and a low of 42.22.

In [54]:
import time

In [55]:
time = time.strftime("%B,%d %Y")

In [56]:
time


Out[56]:
'June,28 2016'

In [57]:
type(time)


Out[57]:
str

In [61]:
requests.post(
        "https://api.mailgun.net/v3/sandbox9fe7853d8f49467cb3233031623028cc.mailgun.org/messages",
        auth=("api", ""),
        data={"from": "Mailgun Sandbox <postmaster@sandbox9fe7853d8f49467cb3233031623028cc.mailgun.org>",
              "to": "sasha kandrach <skkandrach@hotomail.com.com>",
              "subject": "8AM Weather forecast:" + time,
              "text": mail_text })


Out[61]:
<Response [401]>

In [ ]:


In [ ]: