first commit
This commit is contained in:
44
main.py
Normal file
44
main.py
Normal file
@ -0,0 +1,44 @@
|
||||
from flask import Flask, render_template, request, jsonify
|
||||
import requests
|
||||
|
||||
app = Flask(__name__)
|
||||
BASE_URL = "https://meteo.cbpio.pl"
|
||||
|
||||
@app.route("/")
|
||||
def index():
|
||||
return render_template("index.html")
|
||||
|
||||
@app.route("/get_weather", methods=["POST"])
|
||||
def get_weather():
|
||||
data = request.get_json()
|
||||
lat = data.get("lat")
|
||||
lon = data.get("lon")
|
||||
|
||||
if lat is None or lon is None:
|
||||
return jsonify({"error": "Missing coordinates"}), 400
|
||||
|
||||
try:
|
||||
current = requests.get(f"{BASE_URL}/weather/geo", params={"latitude": lat, "longitude": lon}).json()
|
||||
forecast = requests.get(f"{BASE_URL}/forecast/geo", params={
|
||||
"latitude": lat,
|
||||
"longitude": lon,
|
||||
"days": 7
|
||||
}).json()
|
||||
hourly = requests.get(f"{BASE_URL}/forecast/hourly/geo", params={
|
||||
"latitude": lat,
|
||||
"longitude": lon,
|
||||
"hours": 24
|
||||
}).json()
|
||||
|
||||
return jsonify({
|
||||
"current": current,
|
||||
"daily": forecast,
|
||||
"hourly": hourly
|
||||
})
|
||||
except Exception as e:
|
||||
print("❌ Error fetching data:", e)
|
||||
return jsonify({"error": str(e)}), 500
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(debug=True)
|
||||
|
Reference in New Issue
Block a user