
Dieses Python-Script kompiliert die Match-Daten von einer ESPN-API (aktuelle Spiele und aktuelle Tore als Summe) und exportiert diese als TXT-Datei.
In meinem Fall ist es als Videolooper-App angelegt, bei dem die TXT-Datei in einen Imagemagick-Command incooperiert wird und am Ende mit FFMPEG als Videodatei (rotiert um 90 Grad) erstellt wird und über Videolooper abgespielt wird. Aktualisierung aller drei Minuten.
#!/usr/bin/env python3
"""
Fetches all FIFA World Cup 2026 results from the ESPN API,
sums every goal scored across the entire tournament,
and writes today's scores + overall total to txt.
"""
import subprocess
import json
from datetime import datetime, date, timedelta
API_BASE = "https://site.api.espn.com/apis/site/v2/sports/soccer/fifa.world/scoreboard"
OUTPUT = "espn_data.txt"
# World Cup 2026: June 11 – July 19
WC_START = date(2026, 6, 11)
WC_END = date(2026, 7, 19)
TODAY = date.today()
def fetch_scores(day: date):
"""Returns list of (home_abbr, away_abbr, home_score, away_score, state, detail)."""
url = f"{API_BASE}?dates={day.strftime('%Y%m%d')}"
raw = subprocess.run(["curl", "-s", url], capture_output=True).stdout
try:
data = json.loads(raw)
except json.JSONDecodeError:
return []
results = []
for event in data.get("events", []):
comp = event["competitions"][0]
status = comp["status"]["type"]
state = status["state"]
detail = status.get("shortDetail", "")
teams = comp["competitors"]
home = next(t for t in teams if t["homeAway"] == "home")
away = next(t for t in teams if t["homeAway"] == "away")
results.append((
home["team"]["abbreviation"],
away["team"]["abbreviation"],
int(home["score"]),
int(away["score"]),
state,
detail,
))
return results
# --- Collect all completed/live games up to today ---
total_goals = 0
games_counted = 0
today_lines = []
d = WC_START
while d <= min(TODAY, WC_END):
for home_abbr, away_abbr, hs, as_, state, detail in fetch_scores(d):
if state in ("in", "post"):
goals = hs + as_
total_goals += goals
games_counted += 1
if d == TODAY:
today_lines.append(
f" {home_abbr} vs {away_abbr:<6} {hs}:{as_} -> {goals} Tor{'e' if goals != 1 else ''} "
)
elif d == TODAY:
today_lines.append(
f" {home_abbr} vs {away_abbr:<6} "
)
d += timedelta(days=1)
# --- Build output ---
lines = []
lines.append(f"FIFA World Cup 2026 \n({datetime.now().strftime('%Y-%m-%d %H:%M')} Uhr)")
lines.append("=" * 55)
if today_lines:
lines.append(f"Heute ({TODAY}):")
lines.extend(today_lines)
lines.append("")
lines.append("-" * 55)
lines.append(f"{total_goals} Tore in {games_counted} Spielen")
output = "\n".join(lines)
print(output)
with open(OUTPUT, "w", encoding="utf-8") as f:
f.write(output + "\n")
print(f"\n-> Gespeichert als {OUTPUT}")