commit c68956c0788320481614348fabdce9a2c82deac0 Author: josh Date: Sat Jan 24 16:29:30 2026 -0500 init diff --git a/app.py b/app.py new file mode 100644 index 0000000..a7e5866 --- /dev/null +++ b/app.py @@ -0,0 +1,192 @@ +from flask import Flask, render_template_string, jsonify +from datetime import date, datetime +import requests + +app = Flask(__name__) + +# ---- CONFIG ---- +LOCATION_NAME = "South Bend, IN (46617)" +LAT = 41.6764 +LON = -86.2520 + +MAX_SNOW_INCHES = 24 + +OPEN_METEO_URL = "https://api.open-meteo.com/v1/forecast" + + +def get_today_snowfall(): + params = { + "latitude": LAT, + "longitude": LON, + "hourly": "snowfall", + "timezone": "America/Indiana/Indianapolis" + } + + try: + r = requests.get(OPEN_METEO_URL, params=params, timeout=5) + r.raise_for_status() + data = r.json() + + today = date.today().isoformat() + snowfall_cm = 0.0 + snowing_now = False + + for t, s in zip(data["hourly"]["time"], data["hourly"]["snowfall"]): + if t.startswith(today): + snowfall_cm += s + if s > 0: + snowing_now = True + + inches = round(snowfall_cm / 2.54, 1) + return inches, snowing_now + + except Exception: + return 0.0, False + + +HTML = """ + + + + + Are We Buried? + + + + + +
+ +
+ + + +
+
+ +
+

Are We Buried?

+
-- in
+
{{ location }} • {{ today }}
+
Last updated: --
+
+ + + + +""" + +@app.route("/") +def index(): + return render_template_string( + HTML, + today=date.today().strftime("%B %d, %Y"), + location=LOCATION_NAME + ) + + +@app.route("/api/snowfall") +def snowfall_api(): + inches, snowing = get_today_snowfall() + + return jsonify({ + "location": LOCATION_NAME, + "lat": LAT, + "lon": LON, + "inches": inches, + "max_inches": MAX_SNOW_INCHES, + "snowing": snowing, + "updated": datetime.now().isoformat() + }) + + +if __name__ == "__main__": + app.run(debug=True) \ No newline at end of file