From bb5989a7aad3b0f641d302320d8dd0244be310e5 Mon Sep 17 00:00:00 2001 From: Igor Chubin Date: Sat, 27 Oct 2018 23:55:14 +0200 Subject: [PATCH] added lib/weather_data.py --- lib/weather_data.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 lib/weather_data.py diff --git a/lib/weather_data.py b/lib/weather_data.py new file mode 100644 index 0000000..9973e70 --- /dev/null +++ b/lib/weather_data.py @@ -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