Spaces:
Sleeping
Sleeping
PandaArtStation
commited on
Commit
•
5f42447
1
Parent(s):
cce65f0
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flask import Flask, request, jsonify
|
2 |
+
import requests
|
3 |
+
|
4 |
+
app = Flask(__name__)
|
5 |
+
|
6 |
+
WEATHER_API_URL = "http://api.openweathermap.org/data/2.5/weather"
|
7 |
+
API_KEY = "56ad42c3b5c09e6b9ef92284bb5b56ad"
|
8 |
+
|
9 |
+
@app.route('/weather', methods=['GET'])
|
10 |
+
def get_weather():
|
11 |
+
city = request.args.get('city', '') # Получаем город из параметров запроса
|
12 |
+
params = {
|
13 |
+
'q': city,
|
14 |
+
'appid': API_KEY,
|
15 |
+
'units': 'metric' # Метрическая система (Цельсии)
|
16 |
+
}
|
17 |
+
response = requests.get(WEATHER_API_URL, params=params)
|
18 |
+
if response.status_code == 200:
|
19 |
+
return jsonify(response.json())
|
20 |
+
else:
|
21 |
+
return jsonify({'error': 'Не удалось получить прогноз погоды'}), 500
|
22 |
+
|
23 |
+
if __name__ == '__main__':
|
24 |
+
app.run(debug=True)
|
25 |
+
|