From 3ab7b4ef0db94a91b9113829f6a44f399320e832 Mon Sep 17 00:00:00 2001 From: Paula K Date: Wed, 16 Feb 2022 22:37:43 +0100 Subject: [PATCH] Add route to access OpenWeatherMap through cloud --- cloud/app.py | 12 ++++++++++++ cloud/config.py | 2 ++ 2 files changed, 14 insertions(+) diff --git a/cloud/app.py b/cloud/app.py index afdd73a..f61b0bb 100644 --- a/cloud/app.py +++ b/cloud/app.py @@ -8,6 +8,7 @@ from flask_migrate import Migrate from functools import wraps import jwt +import requests from config import Config @@ -327,5 +328,16 @@ def addPredictedValues(): return str(0) +@app.route('/weather', methods=['POST']) +@token_required +def weather(): + api = app.config['OWM_API_KEY'] + + response = requests.get('http://api.openweathermap.org/data/2.5/weather?q =' + 'modena' + '&appid =' + api) + source = response.content + print(source) + return source + + if __name__ == '__main__': app.run() diff --git a/cloud/config.py b/cloud/config.py index 789eb0c..321e11a 100644 --- a/cloud/config.py +++ b/cloud/config.py @@ -38,3 +38,5 @@ class Config: # JWT TOKEN_SECRET_KEY = environ['SECRET_KEY'] TOKEN_BRIDGE_IDS = environ['BRIDGE_TOKEN_IDs'] + # OpenWeatherMap + OWM_API_KEY = environ['OWM_API_KEY']