This commit is contained in:
2026-01-24 16:29:30 -05:00
commit c68956c078

192
app.py Normal file
View File

@@ -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 = """
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Are We Buried?</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
html, body {
margin: 0; padding: 0; height: 100%;
background: #0b1320; color: #fff;
font-family: system-ui, sans-serif;
overflow: hidden;
}
.snowfall { position: fixed; inset: 0; pointer-events: none; z-index: 1; }
.flake {
position: absolute; top: -10px;
width: 6px; height: 6px;
background: rgba(255,255,255,0.9);
border-radius: 50%;
animation: fall linear infinite;
}
@keyframes fall { to { transform: translateY(110vh); } }
.snow-wrapper {
position: fixed; bottom: 0; left: 0;
width: 100%; height: 0%;
transition: height 2s ease-out;
z-index: 2; overflow: hidden;
}
svg { position: absolute; top: -80px; width: 100%; height: 160px; }
.snow-body {
position: absolute; bottom: 0; width: 100%; height: 100%;
background:
radial-gradient(circle at 20% 20%, #fff 0 2px, transparent 3px),
radial-gradient(circle at 60% 40%, #f2f8ff 0 2px, transparent 3px),
radial-gradient(circle at 80% 30%, #fff 0 2px, transparent 3px),
linear-gradient(#fff, #e6f2ff);
background-size: 40px 40px, 60px 60px, 50px 50px, 100% 100%;
}
.container {
position: relative; z-index: 3; height: 100%;
display: flex; flex-direction: column;
justify-content: center; align-items: center;
gap: 0.75rem; pointer-events: none;
}
h1 { font-size: clamp(2.5rem, 6vw, 4rem); margin: 0; }
.amount { font-size: clamp(1.5rem, 4vw, 2.5rem); opacity: 0.9; }
.meta { opacity: 0.6; font-size: 0.9rem; }
</style>
</head>
<body>
<div class="snowfall" id="snowfall"></div>
<div class="snow-wrapper" id="snowWrapper">
<svg viewBox="0 0 100 20" preserveAspectRatio="none">
<path d="M0 10 Q 15 2 30 10 T 60 10 T 100 10 L 100 20 L 0 20 Z" fill="#ffffff" />
</svg>
<div class="snow-body"></div>
</div>
<div class="container">
<h1>Are We Buried?</h1>
<div class="amount" id="amount">-- in</div>
<div class="meta" id="meta">{{ location }} • {{ today }}</div>
<div class="meta" id="updated">Last updated: --</div>
</div>
<script>
let flakesStarted = false;
async function loadSnow() {
const res = await fetch('/api/snowfall');
const data = await res.json();
document.getElementById('amount').textContent = data.inches + ' inches today';
const percent = Math.min(data.inches / data.max_inches, 1);
document.getElementById('snowWrapper').style.height = (percent * 100) + '%';
const now = new Date();
document.getElementById('updated').textContent =
'Last updated: ' + now.toLocaleTimeString();
if (data.snowing && !flakesStarted) {
spawnSnowflakes();
flakesStarted = true;
}
}
function spawnSnowflakes() {
const container = document.getElementById('snowfall');
const flakes = 90;
for (let i = 0; i < flakes; i++) {
const flake = document.createElement('div');
flake.className = 'flake';
flake.style.left = Math.random() * 100 + 'vw';
flake.style.animationDuration = 5 + Math.random() * 10 + 's';
flake.style.opacity = Math.random();
flake.style.transform = `scale(${Math.random() + 0.5})`;
container.appendChild(flake);
}
}
loadSnow();
setInterval(loadSnow, 10 * 60 * 1000);
</script>
</body>
</html>
"""
@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)