weather: use requests library over urllib/json
This commit is contained in:
		
							parent
							
								
									90d20dfe75
								
							
						
					
					
						commit
						a314809671
					
				| @ -1,9 +1,8 @@ | |||||||
| # coding: utf-8 | # coding: utf-8 | ||||||
| 
 | 
 | ||||||
| import json |  | ||||||
| import logging | import logging | ||||||
| import re | import re | ||||||
| import urllib.request, urllib.error, urllib.parse | import requests | ||||||
| 
 | 
 | ||||||
| from django.conf import settings | from django.conf import settings | ||||||
| 
 | 
 | ||||||
| @ -22,8 +21,8 @@ def get_conditions_for_query(queryitems): | |||||||
|     try: |     try: | ||||||
|         url = wu_base_url + ('{0:s}/q/{1:s}.json'.format('conditions', query)) |         url = wu_base_url + ('{0:s}/q/{1:s}.json'.format('conditions', query)) | ||||||
|         log.debug("calling %s", url) |         log.debug("calling %s", url) | ||||||
|         json_resp = urllib.request.urlopen(url) |         resp = requests.get(url) | ||||||
|         condition_data = json.load(json_resp) |         condition_data = resp.json() | ||||||
|     except IOError as e: |     except IOError as e: | ||||||
|         log.error("error while making conditions query") |         log.error("error while making conditions query") | ||||||
|         log.exception(e) |         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 |     # condition data is loaded. the rest of this is obviously specific to | ||||||
|     # http://www.wunderground.com/weather/api/d/docs?d=data/conditions |     # 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: |     try: | ||||||
|         # just see if we have current_observation data |         # just see if we have current_observation data | ||||||
| @ -135,8 +134,8 @@ def get_forecast_for_query(queryitems): | |||||||
| 
 | 
 | ||||||
|     try: |     try: | ||||||
|         url = wu_base_url + ('{0:s}/q/{1:s}.json'.format('forecast', query)) |         url = wu_base_url + ('{0:s}/q/{1:s}.json'.format('forecast', query)) | ||||||
|         json_resp = urllib.request.urlopen(url) |         resp = requests.get(url) | ||||||
|         forecast_data = json.load(json_resp) |         forecast_data = resp.json() | ||||||
|     except IOError as e: |     except IOError as e: | ||||||
|         log.error("error while making forecast query") |         log.error("error while making forecast query") | ||||||
|         log.exception(e) |         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 |     # forecast data is loaded. the rest of this is obviously specific to | ||||||
|     # http://www.wunderground.com/weather/api/d/docs?d=data/forecast |     # 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: |     try: | ||||||
|         # just see if we have forecast data |         # just see if we have forecast data | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user