-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
python call open weather map and return json
- Loading branch information
1 parent
eaf0b60
commit 1f5d69c
Showing
3 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.env |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from flask import Flask, request | ||
import requests | ||
import os | ||
|
||
from flask import jsonify | ||
from flask_cors import CORS | ||
|
||
|
||
app = Flask(__name__) | ||
CORS(app) | ||
|
||
@app.route('/api/weather/get_weather_data', methods=['GET']) | ||
def get_weather_data(): | ||
|
||
lat = request.args.get('lat') | ||
lng = request.args.get('lng') | ||
base_url = "http://api.openweathermap.org/data/2.5/weather" | ||
|
||
## Define the parameters | ||
params = { | ||
'lat': lat, | ||
'lon': lng, | ||
'appid': os.getenv("OPENWEATHERAPIKEY") | ||
} | ||
|
||
## Send GET request | ||
response = requests.get(base_url, params=params) | ||
|
||
## Convert the response to JSON | ||
weather_data = response.json() | ||
|
||
return jsonify(weather_data) | ||
|
||
|
||
if __name__ == '__main__': | ||
app.run(debug=True) |