From 2f73663b212a2fd8a6a8a35c8ee3361dec6996db Mon Sep 17 00:00:00 2001 From: root Date: Tue, 15 Jul 2025 10:18:13 +0200 Subject: [PATCH] first commit --- main.py | 44 ++++++ templates/index.html | 316 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 360 insertions(+) create mode 100644 main.py create mode 100644 templates/index.html diff --git a/main.py b/main.py new file mode 100644 index 0000000..bb83f41 --- /dev/null +++ b/main.py @@ -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) + diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..368dde6 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,316 @@ + + + + + Pogoda Web + + + + + + +
+

🌦️ Pogoda Web

+

Kliknij na mapie lub wyszukaj miasto, aby zobaczyć prognozę pogody

+
+
+
+ + +
+
+
Kliknij na mapie lub wyszukaj miasto, aby zobaczyć pogodę.
+ + +
+ + + + + +