Ajoute un journal par utilisateur des notifications ntfy et de la présence Tasker
Chaque utilisateur a désormais son propre fichier logs.json dans son
dossier users/<id>/, alimenté automatiquement quand un rappel ntfy est
envoyé (ou échoue) et quand Tasker signale une arrivée ou un départ.
Une nouvelle page /logs, accessible depuis la nav, affiche ces entrées
avec filtres (Tout / Notifications / Présence), et le journal tourne à
500 entrées pour rester compact.
💘 Generated with Crush
Assisted-by: Crush:glm-5.2
This commit is contained in:
@ -4,14 +4,14 @@ import logging
|
||||
import urllib.request
|
||||
from datetime import datetime
|
||||
|
||||
from models import list_users, load_notif_config, load_presence, load_week_pointages
|
||||
from models import list_users, load_notif_config, load_presence, load_week_pointages, append_log
|
||||
|
||||
logger = logging.getLogger("pointeuse.notifications")
|
||||
|
||||
CHECK_INTERVAL_SECONDS = 300
|
||||
|
||||
|
||||
def send_ntfy(server: str, topic: str, message: str, title: str):
|
||||
def send_ntfy(server: str, topic: str, message: str, title: str, user_id: str | None = None):
|
||||
req = urllib.request.Request(
|
||||
f"{server}/{topic}",
|
||||
data=message.encode("utf-8"),
|
||||
@ -21,8 +21,12 @@ def send_ntfy(server: str, topic: str, message: str, title: str):
|
||||
try:
|
||||
urllib.request.urlopen(req, timeout=10).close()
|
||||
logger.info("notif ntfy envoyée: server=%r topic=%r title=%r", server, topic, title)
|
||||
if user_id:
|
||||
append_log(user_id, "notif", "envoyée", f"{title} — {message}")
|
||||
except Exception:
|
||||
logger.exception("échec de l'envoi ntfy: server=%r topic=%r title=%r", server, topic, title)
|
||||
if user_id:
|
||||
append_log(user_id, "notif", "échec", f"{title} — {message}")
|
||||
# best-effort: a missed reminder isn't worth crashing the loop
|
||||
|
||||
|
||||
@ -55,10 +59,18 @@ async def check_user(user_id: str, now: datetime):
|
||||
|
||||
if presence.get("present") and not jour.get("matin_entree"):
|
||||
logger.info("rappel 'pense à pointer' pour %r", user_id)
|
||||
await asyncio.to_thread(send_ntfy, server, topic, "Tu es dans les locaux mais pas encore pointé ce matin.", "⏰ Pense à pointer")
|
||||
await asyncio.to_thread(
|
||||
send_ntfy, server, topic,
|
||||
"Tu es dans les locaux mais pas encore pointé ce matin.",
|
||||
"⏰ Pense à pointer", user_id,
|
||||
)
|
||||
elif not presence.get("present") and jour.get("matin_entree") and not jour.get("aprem_sortie"):
|
||||
logger.info("rappel 'pense à dépointer' pour %r", user_id)
|
||||
await asyncio.to_thread(send_ntfy, server, topic, "Tu as quitté les locaux sans dépointer la sortie.", "⏰ Pense à dépointer")
|
||||
await asyncio.to_thread(
|
||||
send_ntfy, server, topic,
|
||||
"Tu as quitté les locaux sans dépointer la sortie.",
|
||||
"⏰ Pense à dépointer", user_id,
|
||||
)
|
||||
|
||||
|
||||
async def reminder_loop():
|
||||
|
||||
Reference in New Issue
Block a user