File size: 876 Bytes
02c5f81
 
5f42447
02c5f81
5f42447
02c5f81
 
5f42447
02c5f81
 
 
 
 
 
 
5f42447
02c5f81
5f42447
 
 
 
 
02c5f81
5f42447
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from flask import Flask, request, jsonify
import requests

    app = Flask(__name__)

    WEATHER_API_URL = "http://api.openweathermap.org/data/2.5/weather"
    API_KEY = "56ad42c3b5c09e6b9ef92284bb5b56ad"

    @app.route('/weather', methods=['GET'])
def get_weather():
    city = request.args.get('city', '')  # Получаем город из параметров запроса
    params = {
        'q': city,
        'appid': API_KEY,
        'units': 'metric'  # Метрическая система (Цельсии)
         }
    response = requests.get(WEATHER_API_URL, params=params)
         if response.status_code == 200:
             return jsonify(response.json())
         else:
             return jsonify({'error': 'Не удалось получить прогноз погоды'}), 500

    if __name__ == '__main__':
         app.run(debug=True)