weather: use requests library over urllib/json

This commit is contained in:
Brian S. Stephan 2016-01-16 19:38:24 -06:00
parent 90d20dfe75
commit a314809671
1 changed files with 7 additions and 8 deletions

View File

@ -1,9 +1,8 @@
# coding: utf-8
import json
import logging
import re
import urllib.request, urllib.error, urllib.parse
import requests
from django.conf import settings
@ -22,8 +21,8 @@ def get_conditions_for_query(queryitems):
try:
url = wu_base_url + ('{0:s}/q/{1:s}.json'.format('conditions', query))
log.debug("calling %s", url)
json_resp = urllib.request.urlopen(url)
condition_data = json.load(json_resp)
resp = requests.get(url)
condition_data = resp.json()
except IOError as e:
log.error("error while making conditions query")
log.exception(e)
@ -31,7 +30,7 @@ def get_conditions_for_query(queryitems):
# condition data is loaded. the rest of this is obviously specific to
# http://www.wunderground.com/weather/api/d/docs?d=data/conditions
log.debug(json.dumps(condition_data, sort_keys=True, indent=4))
log.debug(condition_data)
try:
# just see if we have current_observation data
@ -135,8 +134,8 @@ def get_forecast_for_query(queryitems):
try:
url = wu_base_url + ('{0:s}/q/{1:s}.json'.format('forecast', query))
json_resp = urllib.request.urlopen(url)
forecast_data = json.load(json_resp)
resp = requests.get(url)
forecast_data = resp.json()
except IOError as e:
log.error("error while making forecast query")
log.exception(e)
@ -144,7 +143,7 @@ def get_forecast_for_query(queryitems):
# forecast data is loaded. the rest of this is obviously specific to
# http://www.wunderground.com/weather/api/d/docs?d=data/forecast
log.debug(json.dumps(forecast_data, sort_keys=True, indent=4))
log.debug(forecast_data)
try:
# just see if we have forecast data