Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add route to access OpenWeatherMap through cloud #55

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions cloud/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from flask_migrate import Migrate
from functools import wraps
import jwt
import requests

from config import Config

Expand Down Expand Up @@ -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()
2 changes: 2 additions & 0 deletions cloud/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']