Spaces:
Sleeping
Sleeping
Download scripts/fetch_data.py from FC-Bit/arkanum: direct link, hf CLI and curl.
- Browser
- Download file 2.37 kB
-
https://huggingface.co/spaces/FC-Bit/arkanum/resolve/main/scripts/fetch_data.py
- Command line
-
hf download hf://spaces/FC-Bit/arkanum/scripts/fetch_data.py
-
curl -L -o fetch_data.py https://huggingface.co/spaces/FC-Bit/arkanum/resolve/main/scripts/fetch_data.py
2.37 kB
| """ | |
| Daten-Download Script | |
| ====================== | |
| Lädt Regelwerke und FAQs herunter und bereitet sie für die Ingestion vor. | |
| Verwendung: | |
| python scripts/fetch_data.py --game stalker | |
| """ | |
| import argparse | |
| import os | |
| import requests | |
| from tqdm import tqdm | |
| SOURCES = { | |
| "stalker": { | |
| "rulebook_v1": { | |
| "url": "https://awakenrealms.com/images/download/Stalker/STALKER_CB_Rulebook_280x280mm_bleed3mm%20%5B44%20pages%5D_lowres2.pdf", | |
| "filename": "rulebook_v1.pdf", | |
| }, | |
| "faq_v1": { | |
| "url": "https://awakenrealms.com/images/download/Stalker/STALKER_others_FAQ_297x210mm_bleed3mm%20%5B5%20pages%5D.pdf", | |
| "filename": "faq_v1_2025-01-15.pdf", | |
| }, | |
| # Zone Survival Rulebook URL noch zu ergänzen | |
| } | |
| } | |
| def fetch_game_data(game: str, output_dir: str = "data/raw") -> None: | |
| """ | |
| Lädt alle Dokumente für ein Spiel herunter. | |
| Args: | |
| game: Spielname (z.B. "stalker") | |
| output_dir: Basisverzeichnis für die Downloads | |
| """ | |
| if game not in SOURCES: | |
| raise ValueError(f"Unbekanntes Spiel: {game}. Verfügbar: {list(SOURCES.keys())}") | |
| game_dir = os.path.join(output_dir, game) | |
| os.makedirs(game_dir, exist_ok=True) | |
| for name, source in SOURCES[game].items(): | |
| filepath = os.path.join(game_dir, source["filename"]) | |
| if os.path.exists(filepath): | |
| print(f" ✓ {source['filename']} bereits vorhanden, überspringe.") | |
| continue | |
| print(f" ↓ Lade {source['filename']} herunter...") | |
| resp = requests.get(source["url"], stream=True, timeout=60) | |
| resp.raise_for_status() | |
| total = int(resp.headers.get("content-length", 0)) | |
| with open(filepath, "wb") as f, tqdm(total=total, unit="B", unit_scale=True, desc=source["filename"]) as bar: | |
| for chunk in resp.iter_content(chunk_size=8192): | |
| f.write(chunk) | |
| bar.update(len(chunk)) | |
| print(f" ✓ {source['filename']} gespeichert.") | |
| if __name__ == "__main__": | |
| parser = argparse.ArgumentParser(description="Regelwerk-Daten herunterladen") | |
| parser.add_argument("--game", required=True, help="Spielname (z.B. stalker)") | |
| parser.add_argument("--output-dir", default="data/raw", help="Ausgabeverzeichnis") | |
| args = parser.parse_args() | |
| fetch_game_data(args.game, args.output_dir) | |