Spaces:
Sleeping
Sleeping
PandaArtStation
commited on
Commit
•
02c5f81
1
Parent(s):
a3b99c8
Update main.py
Browse files
main.py
CHANGED
@@ -1,25 +1,25 @@
|
|
1 |
-
|
2 |
-
|
3 |
|
4 |
-
|
5 |
|
6 |
-
|
7 |
-
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
}
|
17 |
-
|
18 |
if response.status_code == 200:
|
19 |
return jsonify(response.json())
|
20 |
else:
|
21 |
return jsonify({'error': 'Не удалось получить прогноз погоды'}), 500
|
22 |
|
23 |
-
|
24 |
app.run(debug=True)
|
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 |
|