added lib/weather_data.py
This commit is contained in:
parent
39ca1cd325
commit
bb5989a7aa
1 changed files with 25 additions and 0 deletions
25
lib/weather_data.py
Normal file
25
lib/weather_data.py
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
"""
|
||||||
|
Weather data source
|
||||||
|
"""
|
||||||
|
|
||||||
|
import json
|
||||||
|
import requests
|
||||||
|
from globals import WWO_KEY
|
||||||
|
|
||||||
|
def get_weather_data(location):
|
||||||
|
"""
|
||||||
|
Get weather data for `location`
|
||||||
|
"""
|
||||||
|
key = WWO_KEY
|
||||||
|
lang = 'en'
|
||||||
|
url = ('/premium/v1/weather.ashx'
|
||||||
|
'?key=%s&q=%s&format=json'
|
||||||
|
'&num_of_days=3&tp=3&lang=%s') % (key, location, lang)
|
||||||
|
url = 'http://127.0.0.1:5001' + url
|
||||||
|
|
||||||
|
response = requests.get(url, timeout=1)
|
||||||
|
try:
|
||||||
|
data = json.loads(response.content)
|
||||||
|
except ValueError:
|
||||||
|
data = {}
|
||||||
|
return data
|
||||||
Loading…
Add table
Reference in a new issue