import urllib.request
import json
import matplotlib.pyplot as plt
import numpy as np
%matplotlib inline
r = urllib.request.urlopen("http://api.wunderground.com/api/SECRETKEY/conditions/q/72034.json")
data = r.read().decode("utf-8")
r.close()
data
'\n{\n "response": {\n "version":"0.1",\n "termsofService":"http://www.wunderground.com/weather/api/d/terms.html",\n "features": {\n "conditions": 1\n }\n\t}\n ,\t"current_observation": {\n\t\t"image": {\n\t\t"url":"http://icons.wxug.com/graphics/wu2/logo_130x80.png",\n\t\t"title":"Weather Underground",\n\t\t"link":"http://www.wunderground.com"\n\t\t},\n\t\t"display_location": {\n\t\t"full":"Conway, AR",\n\t\t"city":"Conway",\n\t\t"state":"AR",\n\t\t"state_name":"Arkansas",\n\t\t"country":"US",\n\t\t"country_iso3166":"US",\n\t\t"zip":"72034",\n\t\t"magic":"1",\n\t\t"wmo":"99999",\n\t\t"latitude":"35.08861160",\n\t\t"longitude":"-92.44194031",\n\t\t"elevation":"97.00000000"\n\t\t},\n\t\t"observation_location": {\n\t\t"full":"Pamela Ln., Conway, Arkansas",\n\t\t"city":"Pamela Ln., Conway",\n\t\t"state":"Arkansas",\n\t\t"country":"US",\n\t\t"country_iso3166":"US",\n\t\t"latitude":"35.093822",\n\t\t"longitude":"-92.415909",\n\t\t"elevation":"315 ft"\n\t\t},\n\t\t"estimated": {\n\t\t},\n\t\t"station_id":"KARCONWA27",\n\t\t"observation_time":"Last Updated on August 31, 1:43 PM CDT",\n\t\t"observation_time_rfc822":"Wed, 31 Aug 2016 13:43:00 -0500",\n\t\t"observation_epoch":"1472668980",\n\t\t"local_time_rfc822":"Wed, 31 Aug 2016 13:56:31 -0500",\n\t\t"local_epoch":"1472669791",\n\t\t"local_tz_short":"CDT",\n\t\t"local_tz_long":"America/Chicago",\n\t\t"local_tz_offset":"-0500",\n\t\t"weather":"Partly Cloudy",\n\t\t"temperature_string":"96.1 F (35.6 C)",\n\t\t"temp_f":96.1,\n\t\t"temp_c":35.6,\n\t\t"relative_humidity":"52%",\n\t\t"wind_string":"From the NNE at 3.2 MPH",\n\t\t"wind_dir":"NNE",\n\t\t"wind_degrees":22,\n\t\t"wind_mph":3.2,\n\t\t"wind_gust_mph":0,\n\t\t"wind_kph":5.1,\n\t\t"wind_gust_kph":0,\n\t\t"pressure_mb":"1016",\n\t\t"pressure_in":"29.99",\n\t\t"pressure_trend":"-",\n\t\t"dewpoint_string":"76 F (24 C)",\n\t\t"dewpoint_f":76,\n\t\t"dewpoint_c":24,\n\t\t"heat_index_string":"109 F (43 C)",\n\t\t"heat_index_f":109,\n\t\t"heat_index_c":43,\n\t\t"windchill_string":"NA",\n\t\t"windchill_f":"NA",\n\t\t"windchill_c":"NA",\n\t\t"feelslike_string":"109 F (43 C)",\n\t\t"feelslike_f":"109",\n\t\t"feelslike_c":"43",\n\t\t"visibility_mi":"10.0",\n\t\t"visibility_km":"16.1",\n\t\t"solarradiation":"--",\n\t\t"UV":"10","precip_1hr_string":"-999.00 in ( 0 mm)",\n\t\t"precip_1hr_in":"-999.00",\n\t\t"precip_1hr_metric":" 0",\n\t\t"precip_today_string":"0.00 in (0 mm)",\n\t\t"precip_today_in":"0.00",\n\t\t"precip_today_metric":"0",\n\t\t"icon":"partlycloudy",\n\t\t"icon_url":"http://icons.wxug.com/i/c/k/partlycloudy.gif",\n\t\t"forecast_url":"http://www.wunderground.com/US/AR/Conway.html",\n\t\t"history_url":"http://www.wunderground.com/weatherstation/WXDailyHistory.asp?ID=KARCONWA27",\n\t\t"ob_url":"http://www.wunderground.com/cgi-bin/findweather/getForecast?query=35.093822,-92.415909",\n\t\t"nowcast":""\n\t}\n}\n'
decoded = json.loads(data)
decoded
{'current_observation': {'UV': '10', 'dewpoint_c': 25, 'dewpoint_f': 76, 'dewpoint_string': '76 F (25 C)', 'display_location': {'city': 'Conway', 'country': 'US', 'country_iso3166': 'US', 'elevation': '88.00000000', 'full': 'Conway, AR', 'latitude': '35.06729889', 'longitude': '-92.38079834', 'magic': '1', 'state': 'AR', 'state_name': 'Arkansas', 'wmo': '99999', 'zip': '72032'}, 'estimated': {}, 'feelslike_c': '43', 'feelslike_f': '109', 'feelslike_string': '109 F (43 C)', 'forecast_url': 'http://www.wunderground.com/US/AR/Conway.html', 'heat_index_c': 43, 'heat_index_f': 109, 'heat_index_string': '109 F (43 C)', 'history_url': 'http://www.wunderground.com/weatherstation/WXDailyHistory.asp?ID=KARCONWA27', 'icon': 'partlycloudy', 'icon_url': 'http://icons.wxug.com/i/c/k/partlycloudy.gif', 'image': {'link': 'http://www.wunderground.com', 'title': 'Weather Underground', 'url': 'http://icons.wxug.com/graphics/wu2/logo_130x80.png'}, 'local_epoch': '1472668001', 'local_time_rfc822': 'Wed, 31 Aug 2016 13:26:41 -0500', 'local_tz_long': 'America/Chicago', 'local_tz_offset': '-0500', 'local_tz_short': 'CDT', 'nowcast': '', 'ob_url': 'http://www.wunderground.com/cgi-bin/findweather/getForecast?query=35.093822,-92.415909', 'observation_epoch': '1472667173', 'observation_location': {'city': 'Pamela Ln., Conway', 'country': 'US', 'country_iso3166': 'US', 'elevation': '315 ft', 'full': 'Pamela Ln., Conway, Arkansas', 'latitude': '35.093822', 'longitude': '-92.415909', 'state': 'Arkansas'}, 'observation_time': 'Last Updated on August 31, 1:12 PM CDT', 'observation_time_rfc822': 'Wed, 31 Aug 2016 13:12:53 -0500', 'precip_1hr_in': '-999.00', 'precip_1hr_metric': ' 0', 'precip_1hr_string': '-999.00 in ( 0 mm)', 'precip_today_in': '0.00', 'precip_today_metric': '0', 'precip_today_string': '0.00 in (0 mm)', 'pressure_in': '29.99', 'pressure_mb': '1016', 'pressure_trend': '-', 'relative_humidity': '56%', 'solarradiation': '--', 'station_id': 'KARCONWA27', 'temp_c': 34.8, 'temp_f': 94.6, 'temperature_string': '94.6 F (34.8 C)', 'visibility_km': '16.1', 'visibility_mi': '10.0', 'weather': 'Partly Cloudy', 'wind_degrees': 337, 'wind_dir': 'NNW', 'wind_gust_kph': 0, 'wind_gust_mph': 0, 'wind_kph': 5.1, 'wind_mph': 3.2, 'wind_string': 'From the NNW at 3.2 MPH', 'windchill_c': 'NA', 'windchill_f': 'NA', 'windchill_string': 'NA'}, 'response': {'features': {'conditions': 1}, 'termsofService': 'http://www.wunderground.com/weather/api/d/terms.html', 'version': '0.1'}}
location = decoded["current_observation"]["observation_location"]["city"]
location
'Pamela Ln., Conway'
temp = decoded["current_observation"]["temp_f"]
print("Current weather is " + str(temp) + " in " + location)
Current weather is 94.6 in Pamela Ln., Conway
r = urllib.request.urlopen("http://api.wunderground.com/api/SECRETKEY/hourly10day/q/AR/Conway.json")
data = r.read().decode("utf-8")
r.close()
decoded = json.loads(data)
time = []
temp = []
feels = []
for e in decoded["hourly_forecast"]:
time.append((float(e['FCTTIME']["epoch"]) -
float(decoded["hourly_forecast"][0]["FCTTIME"]["epoch"])) / 86400)
temp.append((float(e['temp']['english'])))
feels.append(float(e['feelslike']['english']))
plt.plot(time, temp)
plt.plot(time, feels, color="r")
plt.ylim([0, 100])
(0, 100)