diff --git a/app.js b/app.js index 3c3caf5..05a6d67 100644 --- a/app.js +++ b/app.js @@ -13,6 +13,7 @@ let currentGame = null; let allLaraGames = []; let refreshTimer = null; let countdown = 0; +let serverLastFetch = null; /** * Lädt die PGN-Datei und aktualisiert die Anzeige @@ -22,12 +23,19 @@ async function loadPGN() { hideError(); try { - // Lokaler Proxy-Server (python server.py) - const response = await fetch('http://localhost:8111/pgn'); + const [pgnResponse, statusResponse] = await Promise.all([ + fetch('http://localhost:8111/pgn'), + fetch('http://localhost:8111/status').catch(() => null) + ]); - if (!response.ok) throw new Error(`HTTP ${response.status}`); + if (!pgnResponse.ok) throw new Error(`HTTP ${pgnResponse.status}`); - const pgnText = await response.text(); + if (statusResponse && statusResponse.ok) { + const status = await statusResponse.json(); + serverLastFetch = status.last_fetch ? status.last_fetch * 1000 : null; + } + + const pgnText = await pgnResponse.text(); const allGames = parsePGN(pgnText); allLaraGames = filterLaraGames(allGames); @@ -278,9 +286,9 @@ function formatClock(clockStr) { * Update timestamp */ function updateTimestamp() { - const now = new Date(); + const time = serverLastFetch ? new Date(serverLastFetch) : new Date(); document.getElementById('last-update').textContent = - `Letztes Update: ${now.toLocaleTimeString('de-DE')}`; + `Letztes Update: ${time.toLocaleTimeString('de-DE')}`; } /** @@ -293,8 +301,10 @@ function startAutoRefresh() { refreshTimer = setInterval(() => { countdown--; + const mins = Math.floor(countdown / 60); + const secs = countdown % 60; document.getElementById('refresh-timer').textContent = - `Nächste Aktualisierung: ${countdown}s`; + `Nächstes Update in: ${String(mins).padStart(2, '0')}:${String(secs).padStart(2, '0')}`; if (countdown <= 0) { countdown = REFRESH_INTERVAL / 1000; diff --git a/server.py b/server.py index 6b6cea0..7aa0ccb 100644 --- a/server.py +++ b/server.py @@ -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 diff --git a/style.css b/style.css index adf9a31..fcbfda1 100644 --- a/style.css +++ b/style.css @@ -36,6 +36,16 @@ header h1 { color: #aaa; } +#last-update, #refresh-timer { + font-family: 'Courier New', monospace; + font-size: 0.9rem; + color: #4ade80; + background: rgba(0, 0, 0, 0.4); + padding: 4px 10px; + border-radius: 6px; + border: 1px solid rgba(74, 222, 128, 0.2); +} + #refresh-btn { background: #e94560; border: none;