Compare commits
3 commits
fa1ecfa0fb
...
8c2bc0c445
| Author | SHA1 | Date | |
|---|---|---|---|
| 8c2bc0c445 | |||
| cad34711b7 | |||
| ac5b26f767 |
9 changed files with 159 additions and 111 deletions
2
VERSION
2
VERSION
|
|
@ -1 +1 @@
|
||||||
1129
|
1131
|
||||||
|
|
@ -12,7 +12,7 @@ from apscheduler.triggers.cron import CronTrigger
|
||||||
_TZ = ZoneInfo("Europe/Berlin")
|
_TZ = ZoneInfo("Europe/Berlin")
|
||||||
|
|
||||||
from database import db
|
from database import db
|
||||||
from routes.push import send_push_to_user, send_push_to_all
|
from routes.push import send_push_to_user, send_push_to_all, send_push
|
||||||
import weather
|
import weather
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
@ -708,45 +708,70 @@ async def _job_poison_archive():
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
async def _job_weather_alert():
|
async def _job_weather_alert():
|
||||||
"""
|
"""
|
||||||
Holt Tagesprognose für mehrere deutsche Städte.
|
STANDORTBEZOGENER Wetter-Alarm.
|
||||||
Sendet Push-Notification wenn:
|
Gruppiert alle Push-Abonnenten nach ihrem letzten bekannten Standort
|
||||||
- Temperatur >= 28°C (Asphalt-Warnung für Pfoten)
|
(gerundet auf 0.1° ≈ 11 km) und holt pro Cluster die lokale Tagesprognose.
|
||||||
- Gewitter wahrscheinlich
|
Sendet nur an die Abonnenten DES JEWEILIGEN Clusters, wenn dort:
|
||||||
Hitze hat Vorrang: Bei Hitze wird kein Gewitter-Push mehr gesendet.
|
- Temperatur >= 28°C (Asphalt-Warnung für Pfoten), oder
|
||||||
|
- Gewitter wahrscheinlich (Hitze hat Vorrang).
|
||||||
|
Abonnenten ohne gespeicherten Standort erhalten keine Wetter-Warnung
|
||||||
|
(besser keine als eine für eine fremde Region).
|
||||||
"""
|
"""
|
||||||
logger.info("Wetter-Alert Job läuft")
|
from collections import defaultdict
|
||||||
try:
|
logger.info("Wetter-Alert Job läuft (standortbezogen)")
|
||||||
summary = await weather.get_weather_summary()
|
|
||||||
except Exception as e:
|
with db() as conn:
|
||||||
logger.error(f"Wetter-Alert: Fehler beim Abruf: {e}")
|
rows = conn.execute(
|
||||||
|
"SELECT * FROM push_subscriptions "
|
||||||
|
"WHERE last_lat IS NOT NULL AND last_lon IS NOT NULL"
|
||||||
|
).fetchall()
|
||||||
|
|
||||||
|
if not rows:
|
||||||
|
logger.info("Wetter-Alert: keine Abonnenten mit Standort.")
|
||||||
|
_log_job("weather_alert", "ok", "Keine Standorte")
|
||||||
return
|
return
|
||||||
|
|
||||||
max_temp = summary["max_temp_c"]
|
# Nach gerundetem Standort clustern → ein Wetter-Abruf pro Cluster
|
||||||
thunderstorm = summary["thunderstorm"]
|
clusters = defaultdict(list)
|
||||||
|
for row in rows:
|
||||||
|
key = (round(row["last_lat"], 1), round(row["last_lon"], 1))
|
||||||
|
clusters[key].append(row)
|
||||||
|
|
||||||
if max_temp >= 28:
|
heat_clusters = thunder_clusters = total_sent = 0
|
||||||
_log_job("weather_alert", "ok", f"Hitze-Push: {max_temp:.0f}°C")
|
for (lat, lon), subs in clusters.items():
|
||||||
sent = send_push_to_all({
|
try:
|
||||||
"type": "weather_heat",
|
alert = await weather.get_day_alert(lat, lon)
|
||||||
"title": "☀️ Heißer Asphalt heute",
|
except Exception as e:
|
||||||
"body": f"Bis {max_temp:.0f}°C heute — Asphalt kann über 50°C heiß werden. Frühmorgens oder abends gassi gehen!",
|
logger.warning(f"Wetter-Alert: Abruf für {lat},{lon} fehlgeschlagen: {e}")
|
||||||
"data": {"tag": "weather-heat"},
|
continue
|
||||||
})
|
|
||||||
logger.info(f"Wetter-Alert Hitze: {max_temp:.1f}°C — {sent} Push gesendet.")
|
|
||||||
return # Kein Gewitter-Push mehr nötig wenn Hitze bereits gemeldet
|
|
||||||
|
|
||||||
if thunderstorm:
|
max_temp = alert["max_temp_c"]
|
||||||
sent = send_push_to_all({
|
payload = None
|
||||||
"type": "weather_thunder",
|
if max_temp is not None and max_temp >= 28:
|
||||||
"title": "⛈️ Gewitter möglich",
|
payload = {
|
||||||
"body": "Heute Gewitter wahrscheinlich. Gassi-Tour früh einplanen und Hund beruhigen.",
|
"type": "weather_heat",
|
||||||
"data": {"tag": "weather-thunder"},
|
"title": "☀️ Heißer Asphalt heute",
|
||||||
})
|
"body": f"Bis {max_temp:.0f}°C heute — Asphalt kann über 50°C heiß werden. Frühmorgens oder abends gassi gehen!",
|
||||||
logger.info(f"Wetter-Alert Gewitter — {sent} Push gesendet.")
|
"data": {"tag": "weather-heat"},
|
||||||
return
|
}
|
||||||
|
heat_clusters += 1
|
||||||
|
elif alert["thunderstorm"]:
|
||||||
|
payload = {
|
||||||
|
"type": "weather_thunder",
|
||||||
|
"title": "⛈️ Gewitter möglich",
|
||||||
|
"body": "Heute Gewitter wahrscheinlich. Gassi-Tour früh einplanen und Hund beruhigen.",
|
||||||
|
"data": {"tag": "weather-thunder"},
|
||||||
|
}
|
||||||
|
thunder_clusters += 1
|
||||||
|
|
||||||
logger.info("Wetter-Alert: Keine Warnung nötig heute.")
|
if payload:
|
||||||
_log_job("weather_alert", "ok", "Keine Warnung")
|
for row in subs:
|
||||||
|
if send_push(row, payload):
|
||||||
|
total_sent += 1
|
||||||
|
|
||||||
|
msg = f"{heat_clusters} Hitze- / {thunder_clusters} Gewitter-Cluster, {total_sent} Push"
|
||||||
|
logger.info(f"Wetter-Alert: {msg}")
|
||||||
|
_log_job("weather_alert", "ok", msg)
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -8179,7 +8179,7 @@ svg.empty-state-icon {
|
||||||
|
|
||||||
/* Frosted-Glass Info-Card (oben in jeder Welt) */
|
/* Frosted-Glass Info-Card (oben in jeder Welt) */
|
||||||
.world-info-card {
|
.world-info-card {
|
||||||
background: rgba(0, 0, 0, var(--wbg-dim, 0.38));
|
background: rgba(0, 0, 0, var(--wbg-dim-top, 0.38));
|
||||||
backdrop-filter: blur(var(--wbg-blur, 18px)) saturate(1.6);
|
backdrop-filter: blur(var(--wbg-blur, 18px)) saturate(1.6);
|
||||||
-webkit-backdrop-filter: blur(var(--wbg-blur, 18px)) saturate(1.6);
|
-webkit-backdrop-filter: blur(var(--wbg-blur, 18px)) saturate(1.6);
|
||||||
border: 1px solid var(--wborder, rgba(99, 130, 220, 0.55));
|
border: 1px solid var(--wborder, rgba(99, 130, 220, 0.55));
|
||||||
|
|
@ -8202,7 +8202,7 @@ svg.empty-state-icon {
|
||||||
|
|
||||||
/* Frosted-Glass Reminder-Card (für Streak, Alerts) */
|
/* Frosted-Glass Reminder-Card (für Streak, Alerts) */
|
||||||
.world-reminder {
|
.world-reminder {
|
||||||
background: rgba(0, 0, 0, var(--wbg-dim, 0.32));
|
background: rgba(0, 0, 0, var(--wbg-dim-top, 0.32));
|
||||||
backdrop-filter: blur(var(--wbg-blur, 12px));
|
backdrop-filter: blur(var(--wbg-blur, 12px));
|
||||||
-webkit-backdrop-filter: blur(var(--wbg-blur, 12px));
|
-webkit-backdrop-filter: blur(var(--wbg-blur, 12px));
|
||||||
border: 1px solid var(--wborder, rgba(99, 130, 220, 0.55));
|
border: 1px solid var(--wborder, rgba(99, 130, 220, 0.55));
|
||||||
|
|
@ -8242,7 +8242,7 @@ svg.empty-state-icon {
|
||||||
|
|
||||||
/* Einzelner Chip: Frosted Glass */
|
/* Einzelner Chip: Frosted Glass */
|
||||||
.world-chip {
|
.world-chip {
|
||||||
background: rgba(0, 0, 0, var(--wbg-dim, 0.35));
|
background: rgba(0, 0, 0, var(--wbg-dim-bottom, 0.35));
|
||||||
backdrop-filter: blur(var(--wbg-blur, 12px));
|
backdrop-filter: blur(var(--wbg-blur, 12px));
|
||||||
-webkit-backdrop-filter: blur(var(--wbg-blur, 12px));
|
-webkit-backdrop-filter: blur(var(--wbg-blur, 12px));
|
||||||
border-radius: 16px;
|
border-radius: 16px;
|
||||||
|
|
@ -8278,8 +8278,10 @@ svg.empty-state-icon {
|
||||||
-webkit-box-orient: vertical;
|
-webkit-box-orient: vertical;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Chip/Banner-Abdunklung + Blur: einheitlich auf allen drei Welten (reduziert) */
|
/* Chip/Banner-Abdunklung + Blur. --wbg-dim-top/-bottom werden in worlds.js
|
||||||
.world-panel { --wbg-dim: 0.14; --wbg-blur: 3px; }
|
adaptiv je nach Bildhelligkeit der oberen/unteren Bildhälfte gesetzt;
|
||||||
|
hier nur die Fallback-Defaults (falls JS nicht misst). */
|
||||||
|
.world-panel { --wbg-dim-top: 0.14; --wbg-dim-bottom: 0.14; --wbg-blur: 3px; }
|
||||||
|
|
||||||
/* Rahmenfarbe je Welt (Alpha einheitlich 0.55) — gilt für Chips + Banner oben
|
/* Rahmenfarbe je Welt (Alpha einheitlich 0.55) — gilt für Chips + Banner oben
|
||||||
Gedämpfte Erdtöne: JETZT orange, HUND naturgrün, WELT blaugrau */
|
Gedämpfte Erdtöne: JETZT orange, HUND naturgrün, WELT blaugrau */
|
||||||
|
|
@ -8306,7 +8308,7 @@ svg.empty-state-icon {
|
||||||
.wj-chip {
|
.wj-chip {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
background: rgba(0, 0, 0, var(--wbg-dim, 0.32));
|
background: rgba(0, 0, 0, var(--wbg-dim-top, 0.32));
|
||||||
backdrop-filter: blur(var(--wbg-blur, 12px));
|
backdrop-filter: blur(var(--wbg-blur, 12px));
|
||||||
-webkit-backdrop-filter: blur(var(--wbg-blur, 12px));
|
-webkit-backdrop-filter: blur(var(--wbg-blur, 12px));
|
||||||
border: 1px solid var(--wborder, rgba(99, 130, 220, 0.55));
|
border: 1px solid var(--wborder, rgba(99, 130, 220, 0.55));
|
||||||
|
|
|
||||||
|
|
@ -86,14 +86,14 @@
|
||||||
<title>Ban Yaro</title>
|
<title>Ban Yaro</title>
|
||||||
|
|
||||||
<!-- Theme + theme-color Statusleiste vor CSS setzen -->
|
<!-- Theme + theme-color Statusleiste vor CSS setzen -->
|
||||||
<script src="/js/boot-early.js?v=1129"></script>
|
<script src="/js/boot-early.js?v=1131"></script>
|
||||||
|
|
||||||
<!-- CSS: Reihenfolge ist wichtig — ?v= zwingt Browser zur Neuladung -->
|
<!-- CSS: Reihenfolge ist wichtig — ?v= zwingt Browser zur Neuladung -->
|
||||||
<link rel="stylesheet" href="/css/design-system.css?v=1129">
|
<link rel="stylesheet" href="/css/design-system.css?v=1131">
|
||||||
<link rel="stylesheet" href="/css/layout.css?v=1129">
|
<link rel="stylesheet" href="/css/layout.css?v=1131">
|
||||||
<link rel="stylesheet" href="/css/components.css?v=1129">
|
<link rel="stylesheet" href="/css/components.css?v=1131">
|
||||||
<link rel="stylesheet" href="/css/utilities.css?v=1129">
|
<link rel="stylesheet" href="/css/utilities.css?v=1131">
|
||||||
<link rel="stylesheet" href="/css/lists.css?v=1129">
|
<link rel="stylesheet" href="/css/lists.css?v=1131">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
|
|
@ -617,11 +617,11 @@
|
||||||
<div id="modal-container"></div>
|
<div id="modal-container"></div>
|
||||||
|
|
||||||
<!-- JS: Reihenfolge ist wichtig — erst Basis, dann Features -->
|
<!-- JS: Reihenfolge ist wichtig — erst Basis, dann Features -->
|
||||||
<script src="/js/api.js?v=1129"></script>
|
<script src="/js/api.js?v=1131"></script>
|
||||||
<script src="/js/ui.js?v=1129"></script>
|
<script src="/js/ui.js?v=1131"></script>
|
||||||
<script src="/js/app.js?v=1129"></script>
|
<script src="/js/app.js?v=1131"></script>
|
||||||
<script src="/js/worlds.js?v=1129"></script>
|
<script src="/js/worlds.js?v=1131"></script>
|
||||||
<script src="/js/offline-indicator.js?v=1129"></script>
|
<script src="/js/offline-indicator.js?v=1131"></script>
|
||||||
|
|
||||||
<!-- Feature-Seiten werden lazy geladen -->
|
<!-- Feature-Seiten werden lazy geladen -->
|
||||||
|
|
||||||
|
|
@ -631,7 +631,7 @@
|
||||||
|
|
||||||
|
|
||||||
<!-- Boot: Offline-Banner + SW-Registration (extrahiert für CSP) -->
|
<!-- Boot: Offline-Banner + SW-Registration (extrahiert für CSP) -->
|
||||||
<script src="/js/boot.js?v=1129"></script>
|
<script src="/js/boot.js?v=1131"></script>
|
||||||
|
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
Router, State-Management, Navigation, Initialisierung.
|
Router, State-Management, Navigation, Initialisierung.
|
||||||
============================================================ */
|
============================================================ */
|
||||||
|
|
||||||
const APP_VER = '1129'; // ← bei jedem Deploy mit Frontend-Änderungen erhöhen
|
const APP_VER = '1131'; // ← bei jedem Deploy mit Frontend-Änderungen erhöhen
|
||||||
const APP_VERSION = '1.6.0'; // ← semantische Version, wird bei make release gesetzt
|
const APP_VERSION = '1.6.0'; // ← semantische Version, wird bei make release gesetzt
|
||||||
window.APP_VER = APP_VER; // global verfügbar für andere Module (z.B. offline-indicator)
|
window.APP_VER = APP_VER; // global verfügbar für andere Module (z.B. offline-indicator)
|
||||||
window.APP_VERSION = APP_VERSION;
|
window.APP_VERSION = APP_VERSION;
|
||||||
|
|
|
||||||
|
|
@ -981,6 +981,7 @@ window.Worlds = (() => {
|
||||||
}
|
}
|
||||||
|
|
||||||
let _bgUrl = null; // aktuell gesetztes Hintergrundbild
|
let _bgUrl = null; // aktuell gesetztes Hintergrundbild
|
||||||
|
let _bgBrightness = null; // { top, bottom } Roh-Helligkeit (0–255) je Bildhälfte für adaptive Abdunklung
|
||||||
|
|
||||||
function _isDarkMode() {
|
function _isDarkMode() {
|
||||||
const t = document.documentElement.getAttribute('data-theme');
|
const t = document.documentElement.getAttribute('data-theme');
|
||||||
|
|
@ -1020,10 +1021,56 @@ window.Worlds = (() => {
|
||||||
// Orientierungswechsel → Bild neu setzen
|
// Orientierungswechsel → Bild neu setzen
|
||||||
window.matchMedia('(orientation: portrait)').addEventListener('change', _applyBgOrientation);
|
window.matchMedia('(orientation: portrait)').addEventListener('change', _applyBgOrientation);
|
||||||
|
|
||||||
// Theme-Wechsel → Overlay-Intensität anpassen
|
// Theme-Wechsel → Overlay-Intensität + adaptive Abdunklung neu anwenden
|
||||||
new MutationObserver(_applyBgOrientation)
|
new MutationObserver(() => { _applyBgOrientation(); _applyAdaptiveDim(); })
|
||||||
.observe(document.documentElement, { attributeFilter: ['data-theme'] });
|
.observe(document.documentElement, { attributeFilter: ['data-theme'] });
|
||||||
|
|
||||||
|
// Helligkeit (0–255) der oberen und unteren Bildhälfte via Mini-Canvas.
|
||||||
|
// Oben = Begrüßungs-Banner + JETZT-Chip-Reihe, unten = Feature-Chips.
|
||||||
|
// Gibt null zurück bei CORS-Tainting oder Fehler (→ Fallback-Abdunklung).
|
||||||
|
function _measureBrightnessRegions(img) {
|
||||||
|
try {
|
||||||
|
const c = document.createElement('canvas');
|
||||||
|
const w = c.width = 32, h = c.height = 32;
|
||||||
|
const ctx = c.getContext('2d', { willReadFrequently: true });
|
||||||
|
ctx.drawImage(img, 0, 0, w, h);
|
||||||
|
const data = ctx.getImageData(0, 0, w, h).data;
|
||||||
|
const half = h / 2;
|
||||||
|
let sumTop = 0, sumBot = 0, nTop = 0, nBot = 0;
|
||||||
|
for (let y = 0; y < h; y++) {
|
||||||
|
for (let x = 0; x < w; x++) {
|
||||||
|
const i = (y * w + x) * 4;
|
||||||
|
const lum = 0.299 * data[i] + 0.587 * data[i + 1] + 0.114 * data[i + 2];
|
||||||
|
if (y < half) { sumTop += lum; nTop++; } else { sumBot += lum; nBot++; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return { top: sumTop / nTop, bottom: sumBot / nBot };
|
||||||
|
} catch { return null; }
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helligkeit (0–255) → Abdunklungs-Alpha. Im Dark Mode liegt zusätzlich
|
||||||
|
// ein 0.45-Overlay über dem Bild, daher wirkt es dort dunkler.
|
||||||
|
function _dimForBrightness(b) {
|
||||||
|
if (_isDarkMode()) b *= 0.55;
|
||||||
|
if (b <= 90) return 0.14;
|
||||||
|
if (b >= 190) return 0.48;
|
||||||
|
return 0.14 + (b - 90) / 100 * (0.48 - 0.14);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setzt --wbg-dim-top/-bottom adaptiv pro Bildbereich: heller Bereich →
|
||||||
|
// mehr Abdunklung (Lesbarkeit), dunkler → wenig.
|
||||||
|
function _applyAdaptiveDim() {
|
||||||
|
const r = _bgBrightness || { top: 110, bottom: 110 };
|
||||||
|
const dimTop = _dimForBrightness(r.top).toFixed(2);
|
||||||
|
const dimBot = _dimForBrightness(r.bottom).toFixed(2);
|
||||||
|
['wp-jetzt', 'wp-hund', 'wp-welt'].forEach(id => {
|
||||||
|
const el = document.getElementById(id);
|
||||||
|
if (!el) return;
|
||||||
|
el.style.setProperty('--wbg-dim-top', dimTop);
|
||||||
|
el.style.setProperty('--wbg-dim-bottom', dimBot);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function _applyBgImage(url) {
|
function _applyBgImage(url) {
|
||||||
const ov = document.getElementById('worlds-overlay');
|
const ov = document.getElementById('worlds-overlay');
|
||||||
const track = document.getElementById('worlds-track');
|
const track = document.getElementById('worlds-track');
|
||||||
|
|
@ -1033,6 +1080,8 @@ window.Worlds = (() => {
|
||||||
toLoad.onload = () => {
|
toLoad.onload = () => {
|
||||||
_hasBgPhoto = true;
|
_hasBgPhoto = true;
|
||||||
_bgUrl = url;
|
_bgUrl = url;
|
||||||
|
_bgBrightness = _measureBrightnessRegions(toLoad);
|
||||||
|
_applyAdaptiveDim();
|
||||||
_applyBgOrientation();
|
_applyBgOrientation();
|
||||||
const hint = document.getElementById('wh-photo-hint');
|
const hint = document.getElementById('wh-photo-hint');
|
||||||
if (hint) {
|
if (hint) {
|
||||||
|
|
@ -1054,6 +1103,8 @@ window.Worlds = (() => {
|
||||||
} else {
|
} else {
|
||||||
_hasBgPhoto = false;
|
_hasBgPhoto = false;
|
||||||
_bgUrl = null;
|
_bgUrl = null;
|
||||||
|
_bgBrightness = { top: 20, bottom: 20 }; // dunkler Fallback-Gradient → minimale Abdunklung
|
||||||
|
_applyAdaptiveDim();
|
||||||
track.style.backgroundImage = '';
|
track.style.backgroundImage = '';
|
||||||
ov.style.backgroundImage = 'linear-gradient(160deg,#1a1f35 0%,#16213e 33%,#1a2535 67%,#0f1921 100%)';
|
ov.style.backgroundImage = 'linear-gradient(160deg,#1a1f35 0%,#16213e 33%,#1a2535 67%,#0f1921 100%)';
|
||||||
ov.style.backgroundSize = '100% 100%';
|
ov.style.backgroundSize = '100% 100%';
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<meta name="color-scheme" content="light dark">
|
<meta name="color-scheme" content="light dark">
|
||||||
<script src="/js/landing-init.js?v=1129"></script>
|
<script src="/js/landing-init.js?v=1131"></script>
|
||||||
<title>Ban Yaro — Die Hunde-App für Deutschland, Österreich & Schweiz</title>
|
<title>Ban Yaro — Die Hunde-App für Deutschland, Österreich & Schweiz</title>
|
||||||
<meta name="description" content="Ban Yaro: Die kostenlose All-in-One Hunde-App für DACH. Tagebuch, Giftköder-Alarm, Training mit KI, Forum, Wurfbörse, Stammbaum, Inzucht-Check — DSGVO-konform, offline-fähig, ohne App Store.">
|
<meta name="description" content="Ban Yaro: Die kostenlose All-in-One Hunde-App für DACH. Tagebuch, Giftköder-Alarm, Training mit KI, Forum, Wurfbörse, Stammbaum, Inzucht-Check — DSGVO-konform, offline-fähig, ohne App Store.">
|
||||||
<meta name="keywords" content="Hunde App, Hunde Community, Wurfbörse, Züchter, Welpen kaufen, Stammbaum Hund, Inzuchtkoeffizient, Hundezucht, Impfpass Hund, Giftköder Alarm, Gassi Community, Hundetraining App, Hunde Forum, Hunde KI, Hundefilm Datenbank, Welpen Marktplatz">
|
<meta name="keywords" content="Hunde App, Hunde Community, Wurfbörse, Züchter, Welpen kaufen, Stammbaum Hund, Inzuchtkoeffizient, Hundezucht, Impfpass Hund, Giftköder Alarm, Gassi Community, Hundetraining App, Hunde Forum, Hunde KI, Hundefilm Datenbank, Welpen Marktplatz">
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
============================================================ */
|
============================================================ */
|
||||||
|
|
||||||
// ← EINZIGE Stelle für die Version — STATIC_ASSETS und CACHE_VERSION leiten sich ab
|
// ← EINZIGE Stelle für die Version — STATIC_ASSETS und CACHE_VERSION leiten sich ab
|
||||||
const VER = '1129';
|
const VER = '1131';
|
||||||
const CACHE_VERSION = `by-v${VER}`;
|
const CACHE_VERSION = `by-v${VER}`;
|
||||||
const CACHE_STATIC = `${CACHE_VERSION}-static`;
|
const CACHE_STATIC = `${CACHE_VERSION}-static`;
|
||||||
const CACHE_TILES = 'ban-yaro-tiles-v1'; // bleibt über SW-Updates erhalten
|
const CACHE_TILES = 'ban-yaro-tiles-v1'; // bleibt über SW-Updates erhalten
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
"""
|
"""
|
||||||
BAN YARO — Wetter via Open-Meteo
|
BAN YARO — Wetter via Open-Meteo
|
||||||
- get_weather_summary(): Push-Job, prüft 5 deutsche Städte
|
- get_day_alert(): standortbezogener Wetter-Alarm-Push (Hitze/Gewitter)
|
||||||
- get_weather_for_location(): API-Endpoint, beliebiger Standort mit TTL-Cache
|
- get_weather_for_location(): API-Endpoint, beliebiger Standort mit TTL-Cache
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
@ -158,67 +158,37 @@ async def get_weather_for_location(lat: float, lon: float) -> dict:
|
||||||
_location_cache[key] = (now, data)
|
_location_cache[key] = (now, data)
|
||||||
return data
|
return data
|
||||||
|
|
||||||
# Wichtige deutsche Städte als Stichprobe
|
|
||||||
CITIES = [
|
|
||||||
{"name": "Berlin", "lat": 52.52, "lon": 13.41},
|
|
||||||
{"name": "München", "lat": 48.14, "lon": 11.58},
|
|
||||||
{"name": "Hamburg", "lat": 53.55, "lon": 10.00},
|
|
||||||
{"name": "Frankfurt", "lat": 50.11, "lon": 8.68},
|
|
||||||
{"name": "Köln", "lat": 50.94, "lon": 6.96},
|
|
||||||
]
|
|
||||||
|
|
||||||
# WMO-Wettercodes 95–99 = Gewitter
|
# WMO-Wettercodes 95–99 = Gewitter
|
||||||
THUNDERSTORM_CODES = {95, 96, 99}
|
THUNDERSTORM_CODES = {95, 96, 99}
|
||||||
|
|
||||||
|
|
||||||
async def get_weather_summary() -> dict:
|
async def get_day_alert(lat: float, lon: float) -> dict:
|
||||||
"""
|
"""
|
||||||
Holt Tagesprognose für mehrere deutsche Städte von Open-Meteo.
|
Tagesprognose (heute) für EINEN Standort — Grundlage für den
|
||||||
Gibt zurück: {"max_temp_c": float, "thunderstorm": bool}
|
standortbezogenen Wetter-Alarm-Push (Hitze / Gewitter).
|
||||||
|
Gibt zurück: {"max_temp_c": float|None, "thunderstorm": bool}
|
||||||
"""
|
"""
|
||||||
max_temp = -999.0
|
url = (
|
||||||
thunderstorm = False
|
"https://api.open-meteo.com/v1/forecast"
|
||||||
|
f"?latitude={lat}&longitude={lon}"
|
||||||
|
"&daily=temperature_2m_max,precipitation_probability_max,weathercode"
|
||||||
|
"&timezone=Europe%2FBerlin&forecast_days=1"
|
||||||
|
)
|
||||||
async with httpx.AsyncClient(timeout=10.0) as client:
|
async with httpx.AsyncClient(timeout=10.0) as client:
|
||||||
for city in CITIES:
|
resp = await client.get(url)
|
||||||
url = (
|
resp.raise_for_status()
|
||||||
"https://api.open-meteo.com/v1/forecast"
|
data = resp.json()
|
||||||
f"?latitude={city['lat']}&longitude={city['lon']}"
|
|
||||||
"&daily=temperature_2m_max,precipitation_probability_max,weathercode"
|
|
||||||
"&timezone=Europe%2FBerlin&forecast_days=1"
|
|
||||||
)
|
|
||||||
try:
|
|
||||||
resp = await client.get(url)
|
|
||||||
resp.raise_for_status()
|
|
||||||
data = resp.json()
|
|
||||||
|
|
||||||
daily = data.get("daily", {})
|
daily = data.get("daily", {})
|
||||||
temps = daily.get("temperature_2m_max", [None])
|
temp = (daily.get("temperature_2m_max") or [None])[0]
|
||||||
precip_probs = daily.get("precipitation_probability_max", [None])
|
precip_prob = (daily.get("precipitation_probability_max") or [None])[0]
|
||||||
weathercodes = daily.get("weathercode", [None])
|
weathercode = (daily.get("weathercode") or [None])[0]
|
||||||
|
|
||||||
temp = temps[0] if temps else None
|
thunderstorm = (
|
||||||
precip_prob = precip_probs[0] if precip_probs else None
|
precip_prob is not None and precip_prob > 50
|
||||||
weathercode = weathercodes[0] if weathercodes else None
|
and weathercode is not None and int(weathercode) in THUNDERSTORM_CODES
|
||||||
|
)
|
||||||
if temp is not None and temp > max_temp:
|
return {"max_temp_c": temp, "thunderstorm": thunderstorm}
|
||||||
max_temp = temp
|
|
||||||
|
|
||||||
if (
|
|
||||||
precip_prob is not None and precip_prob > 50
|
|
||||||
and weathercode is not None and int(weathercode) in THUNDERSTORM_CODES
|
|
||||||
):
|
|
||||||
thunderstorm = True
|
|
||||||
logger.info(f"Gewitter erkannt: {city['name']} (Code {weathercode}, {precip_prob}% Niederschlag)")
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
logger.warning(f"Wetter-Abruf für {city['name']} fehlgeschlagen: {e}")
|
|
||||||
|
|
||||||
if max_temp == -999.0:
|
|
||||||
max_temp = 0.0
|
|
||||||
|
|
||||||
logger.info(f"Wetter-Zusammenfassung: max_temp={max_temp}°C, thunderstorm={thunderstorm}")
|
|
||||||
return {"max_temp_c": max_temp, "thunderstorm": thunderstorm}
|
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue