Skip to content

Commit

Permalink
python call open weather map and return json
Browse files Browse the repository at this point in the history
  • Loading branch information
leon846666 committed Jul 1, 2023
1 parent eaf0b60 commit 1f5d69c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.env
Binary file added __pycache__/app.cpython-311.pyc
Binary file not shown.
36 changes: 36 additions & 0 deletions app.py
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)

0 comments on commit 1f5d69c

Please sign in to comment.