Uhrzeit des letzten PGN-Updates und Countdown bis zum nächsten Update

This commit is contained in:
2026-05-24 14:33:08 +02:00
parent 6d588a4d5c
commit 414732cb7e
3 changed files with 42 additions and 9 deletions

View File

@@ -11,6 +11,7 @@ import sys
import os
import threading
import time
import json
from datetime import datetime
PGN_URL = "https://www.deutsche-schachjugend.de/2026/odjm-d/partien/gesamt-utf8.pgn"
@@ -21,13 +22,18 @@ CACHE_TTL = 30 # Sekunden
os.makedirs(CACHE_DIR, exist_ok=True)
last_fetch_time = None
def fetch_pgn():
"""Lädt die PGN-Datei von der URL als Bytes."""
global last_fetch_time
try:
req = urllib.request.Request(PGN_URL, headers={"User-Agent": "Mozilla/5.0"})
with urllib.request.urlopen(req, timeout=30) as response:
return response.read()
data = response.read()
last_fetch_time = time.time()
return data
except Exception as e:
print(f"[{datetime.now().strftime('%H:%M:%S')}] Fehler beim Laden: {e}")
return None
@@ -83,8 +89,15 @@ class PGNHandler(http.server.BaseHTTPRequestHandler):
self.send_response(200)
self.send_header("Content-Type", "application/json")
self.send_header("Access-Control-Allow-Origin", "*")
self.send_header("Cache-Control", "no-cache")
self.end_headers()
self.wfile.write(b'{"status": "ok"}')
status = {
"status": "ok",
"last_fetch": last_fetch_time,
"cache_ttl": CACHE_TTL,
"server_time": time.time()
}
self.wfile.write(json.dumps(status).encode())
else:
# Statische Dateien aus dem Verzeichnis