Add Lottoland API to Lotto update script
- Added Lottoland API (https://media.lottoland.com/api/drawings/german6aus49) for fetching the latest Lotto 6aus49 draw - Changed strategy to combine both APIs: 1. Lottoland API for the most current draw 2. GitHub Lotto Archive for historical data - Fixed default data path to use /Projekte/Lotto/data - Updated AlleLottozahlen.csv with draw from 2026-01-31 This fixes the issue where the GitHub Lotto Archive was outdated and missing recent draws. Lottoland API provides real-time results. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -31,8 +31,13 @@ class LottoAPIUpdater:
|
||||
self.backup_file = None
|
||||
self.df_existing = None
|
||||
|
||||
# API-Endpoints
|
||||
# API-Endpoints (Lottoland zuerst, da am aktuellsten)
|
||||
self.apis = {
|
||||
'lottoland': {
|
||||
'url': 'https://media.lottoland.com/api/drawings/german6aus49',
|
||||
'name': 'Lottoland API',
|
||||
'parser': self._parse_lottoland
|
||||
},
|
||||
'github': {
|
||||
'url': 'https://johannesfriedrich.github.io/LottoNumberArchive/Lottonumbers_tidy_complete.json',
|
||||
'name': 'GitHub Lotto Archive',
|
||||
@@ -287,6 +292,68 @@ class LottoAPIUpdater:
|
||||
|
||||
return draws
|
||||
|
||||
def _parse_lottoland(self, data: Dict) -> List[Dict]:
|
||||
"""
|
||||
Parst Lottoland API Response.
|
||||
|
||||
Expected format:
|
||||
{
|
||||
"last": {
|
||||
"date": {"day": 31, "month": 1, "year": 2026, ...},
|
||||
"numbers": [8, 19, 30, 37, 38, 49],
|
||||
"superzahl": 3
|
||||
}
|
||||
}
|
||||
"""
|
||||
draws = []
|
||||
|
||||
try:
|
||||
# Lottoland liefert nur die letzte Ziehung unter "last"
|
||||
last_draw = data.get('last')
|
||||
if not last_draw:
|
||||
return draws
|
||||
|
||||
# Datum extrahieren
|
||||
date_info = last_draw.get('date', {})
|
||||
day = date_info.get('day')
|
||||
month = date_info.get('month')
|
||||
year = date_info.get('year')
|
||||
|
||||
if not all([day, month, year]):
|
||||
return draws
|
||||
|
||||
date_obj = datetime(year, month, day)
|
||||
print(f" ✅ Ziehung vom {date_obj.strftime('%Y-%m-%d')} extrahiert")
|
||||
|
||||
# Hauptzahlen (6 Zahlen)
|
||||
numbers = sorted(last_draw.get('numbers', []))
|
||||
if len(numbers) != 6:
|
||||
return draws
|
||||
|
||||
# Superzahl
|
||||
superzahl = last_draw.get('superzahl')
|
||||
if superzahl is None:
|
||||
return draws
|
||||
|
||||
draw = {
|
||||
'datum': date_obj,
|
||||
'Z1': numbers[0],
|
||||
'Z2': numbers[1],
|
||||
'Z3': numbers[2],
|
||||
'Z4': numbers[3],
|
||||
'Z5': numbers[4],
|
||||
'Z6': numbers[5],
|
||||
'SZ': int(superzahl)
|
||||
}
|
||||
|
||||
if self._validate_draw(draw):
|
||||
draws.append(draw)
|
||||
|
||||
except Exception as e:
|
||||
print(f" ⚠️ Parse-Fehler: {e}")
|
||||
|
||||
return draws
|
||||
|
||||
def _validate_draw(self, draw: Dict) -> bool:
|
||||
"""Validiert eine Ziehung."""
|
||||
try:
|
||||
@@ -325,19 +392,31 @@ class LottoAPIUpdater:
|
||||
print("=" * 70)
|
||||
|
||||
all_draws = []
|
||||
success_count = 0
|
||||
|
||||
# Versuche alle APIs (GitHub zuerst, da zuverlässig)
|
||||
for api_name in ['github', 'lottoapi']:
|
||||
draws = self.fetch_from_api(api_name)
|
||||
# Strategie: Lottoland für aktuelle Ziehung, GitHub für Historie
|
||||
# Lottoland liefert nur die neueste Ziehung, GitHub hat die komplette Historie
|
||||
|
||||
if draws:
|
||||
all_draws.extend(draws)
|
||||
print(f" ✅ {len(draws)} Ziehungen von {self.apis[api_name]['name']}")
|
||||
break # Erste erfolgreiche API nutzen
|
||||
else:
|
||||
print(f" ⏭️ Weiter zur nächsten API...")
|
||||
# 1. Versuche Lottoland für die aktuellste Ziehung
|
||||
lottoland_draws = self.fetch_from_api('lottoland')
|
||||
if lottoland_draws:
|
||||
all_draws.extend(lottoland_draws)
|
||||
success_count += 1
|
||||
|
||||
time.sleep(1) # Pause zwischen APIs
|
||||
time.sleep(1)
|
||||
|
||||
# 2. Versuche GitHub für historische Daten
|
||||
github_draws = self.fetch_from_api('github')
|
||||
if github_draws:
|
||||
all_draws.extend(github_draws)
|
||||
success_count += 1
|
||||
|
||||
# 3. Falls beide fehlschlagen, versuche lottoapi als Fallback
|
||||
if success_count == 0:
|
||||
time.sleep(1)
|
||||
lottoapi_draws = self.fetch_from_api('lottoapi')
|
||||
if lottoapi_draws:
|
||||
all_draws.extend(lottoapi_draws)
|
||||
|
||||
if not all_draws:
|
||||
print("\n ❌ Keine Daten von APIs erhalten")
|
||||
@@ -468,7 +547,7 @@ def main():
|
||||
print("=" * 70)
|
||||
print()
|
||||
|
||||
default_file = "/Users/sebastianfrohlich/Library/Mobile Documents/com~apple~CloudDocs/Jupyter Notebooks/Lotto/data/AlleLottozahlen.csv"
|
||||
default_file = "/Users/sebastianfrohlich/Projekte/Lotto/data/AlleLottozahlen.csv"
|
||||
|
||||
if len(sys.argv) > 1:
|
||||
data_file = sys.argv[1]
|
||||
|
||||
Reference in New Issue
Block a user