from __future__ import annotations import bz2 import shutil import sys import urllib.request from pathlib import Path ROOT_DIR = Path(__file__).resolve().parent.parent DATA_DIR = ROOT_DIR / "backend" / "data" BASE_URL = "https://www.fuzzwork.co.uk/dump/latest" REQUIRED_FILES = { "mapDenormalize.csv": f"{BASE_URL}/mapDenormalize.csv.bz2", "mapJumps.csv": f"{BASE_URL}/mapJumps.csv.bz2", "invTypes.csv": f"{BASE_URL}/invTypes.csv.bz2", "mapRegions.csv": f"{BASE_URL}/mapRegions.csv.bz2", } def download_and_extract(file_name: str, url: str) -> None: destination = DATA_DIR / file_name archive_path = destination.with_suffix(destination.suffix + ".bz2") if destination.exists(): print(f"Skipping {file_name}; already exists.") return print(f"Downloading {file_name} from {url}") try: with urllib.request.urlopen(url, timeout=60) as response, archive_path.open("wb") as output_file: shutil.copyfileobj(response, output_file) with bz2.open(archive_path, "rb") as compressed_file, destination.open("wb") as output_file: shutil.copyfileobj(compressed_file, output_file) finally: archive_path.unlink(missing_ok=True) print(f"Wrote {destination}") def main() -> int: DATA_DIR.mkdir(parents=True, exist_ok=True) for file_name, url in REQUIRED_FILES.items(): download_and_extract(file_name, url) print("EVE static data is ready.") return 0 if __name__ == "__main__": raise SystemExit(main())