#!/usr/bin/env python3 """Fetch article 15385, optimize tables with gray borders, PATCH back.""" import json, urllib.request, re TOKEN = "c2hhMjU2Ojc5NDpjYzY0ZTQ4NmVkZGJiMmU1YTk2YTI4YmU4OTcwMzQ5MjRmNjZmMjcyMmRiMGJlM2JhYWI0MDhlNmI4MDZlMmI0" BASE = "https://www.brettspiel-news.de/api/index.php/v1/content/articles" # ── 1. Fetch article ────────────────────────────────────── req = urllib.request.Request(f"{BASE}/15385", headers={ "X-Joomla-Token": TOKEN, "Accept": "application/vnd.api+json" }) resp = urllib.request.urlopen(req) data = json.loads(resp.read()) text = data["data"]["attributes"]["text"] print(f"Fetched article 15385: '{data['data']['attributes']['title']}'") print(f"Text length: {len(text)}") # ── 2. Patch Table 1: "Für wen ist das Spiel?" ──────────── old1 = '

Für wen ist das Spiel?

\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n
✅ Dafür geeignet❌ Eher nicht
Strategie-Fans, die Effizienz liebenCasual-Runden mit 5+ Personen
Solo-Spieler (exzellenter Solo-Modus)Wer epische 3-Stunden-Partien sucht
2–3 Personen (spielt sich am besten)Wer auf Glück statt Taktik steht
Alle, die Die rote Kathedrale mochten 
' new1 = '''

Für wen ist das Spiel?

✅ Dafür geeignet❌ Eher nicht
Strategie-Fans, die Effizienz lieben Casual-Runden mit 5+ Personen
Solo-Spieler (exzellenter Solo-Modus) Wer epische 3-Stunden-Partien sucht
2–3 Personen (spielt sich am besten) Wer auf Glück statt Taktik steht
Alle, die Die rote Kathedrale mochten  
''' if old1 in text: text = text.replace(old1, new1) print("✓ Table 1 replaced") else: print("✗ Table 1 NOT FOUND. Searching...") idx = text.find('Für wen ist das Spiel') if idx >= 0: print(f" Found at position {idx}") print(f" Context: {repr(text[idx:idx+300])}") # ── 3. Patch Table 2: "Die nackten Zahlen" ──────────────── old2 = '

Die nackten Zahlen

\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n
BGG-Rating8.1 / 10
BGG-Weight3.06 / 5 (Kennerspiel)
Spieler1–4 (am besten: 2–3)
Dauerca. 60–80 Minuten
DesignerShei S. & Isra C. (auch Die rote Kathedrale)
VerlagKOSMOS
' new2 = '''

Die nackten Zahlen

BGG-Rating 8.1 / 10
BGG-Weight 3.06 / 5 (Kennerspiel)
Spieler 1–4 (am besten: 2–3)
Dauer ca. 60–80 Minuten
Designer Shei S. & Isra C. (auch Die rote Kathedrale)
Verlag KOSMOS
''' if old2 in text: text = text.replace(old2, new2) print("✓ Table 2 replaced") else: print("✗ Table 2 NOT FOUND. Searching...") idx = text.find('Die nackten Zahlen') if idx >= 0: print(f" Found at position {idx}") print(f" Context: {repr(text[idx:idx+300])}") # ── 4. PATCH back ───────────────────────────────────────── payload = json.dumps({"text": text}).encode() req = urllib.request.Request(f"{BASE}/15385", data=payload, method="PATCH", headers={ "X-Joomla-Token": TOKEN, "Accept": "application/vnd.api+json", "Content-Type": "application/json" }) resp = urllib.request.urlopen(req) result = json.loads(resp.read()) print(f"PATCH status: {resp.status}") print(f"Updated: {result.get('data',{}).get('id')}")