Spaces:
Sleeping
Sleeping
File size: 854 Bytes
1914ad7 02c5f81 d49c3dd 5f42447 1a661e9 5f42447 1a661e9 afdefaf 5f42447 1a661e9 02c5f81 1a661e9 02c5f81 1a661e9 5f42447 1a661e9 5e43e36 |
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
import os
app = Flask(__name__)
WEATHER_API_URL = "http://api.openweathermap.org/data/2.5/weather"
API_KEY = os.getenv('OPENWEATHER_API_KEY')
@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(host="0.0.0.0",port=7860,debug=False) |