mirror of https://github.com/chubin/wttr.in
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
541 B
26 lines
541 B
6 years ago
|
"""
|
||
|
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
|