LuminaWebsite/assets/map/scripts/download_marker_icons.py
Maaxxs c5213b5736 Karte: replace the tactical map with the interactive map viewer
The Karte page now embeds a standalone viewer (assets/map/) covering all ten
regions - Verteron, Altgard, Elthen, Morheim, Poeta, Ishalgen and the
Reshanta maps - with markers and category filters from interactivemap.app.
map.php loads it in an iframe because its stylesheet restyles body, button
and * globally and would otherwise break the site layout.

The tile, marker and icon data (~230 MB, ~39,000 files) is kept out of Git
and uploaded by FTP; the README explains where it comes from.

Removed with it: own markers and categories, tactic layers, the in-browser
map builder, the tile/stitch/viewer tools, the bundled Leaflet, the four map
tables in schema.sql and the map.manage / map.tactics permissions. Existing
databases keep their old map tables untouched.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-21 06:54:17 +02:00

151 lines
No EOL
5.3 KiB
Python

#!/usr/bin/env python3
"""Download all unique marker icon graphics from interactivemap.app.
Scans all local marker JSON files to find unique icon image paths, then
downloads each icon and saves it locally for the map viewer to use.
Usage:
python download_marker_icons.py # Download all icons
python download_marker_icons.py -o ./icons # Custom output directory
"""
import argparse
import json
import os
import sys
import time
import urllib.error
import urllib.request
from concurrent.futures import ThreadPoolExecutor, as_completed
BASE_URL = "https://interactivemap.app"
USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) aion2-icon-downloader/1.0"
def collect_unique_icons(markers_dir):
"""Scan all marker JSON files and collect unique icon image paths."""
print(f"Scanning for icons in: {markers_dir}")
if not os.path.exists(markers_dir):
print(f"Error: Markers directory not found: {markers_dir}")
return set()
icons = set()
json_files = [f for f in os.listdir(markers_dir) if f.endswith('_markers.json')]
print(f"Found {len(json_files)} marker files")
for filename in json_files:
filepath = os.path.join(markers_dir, filename)
try:
with open(filepath, 'r', encoding='utf-8') as f:
data = json.load(f)
markers = data.get('markers', [])
for marker in markers:
props = marker.get('properties', {})
icon_image = props.get('icon_image')
if icon_image:
# Remove query string (version parameter)
clean_path = icon_image.split('?')[0]
icons.add(clean_path)
except Exception as e:
print(f" Warning: Failed to read {filename}: {e}")
print(f"Found {len(icons)} unique icon paths")
return icons
def download_icon(icon_path, out_dir):
"""Download a single icon. Returns status string."""
# Extract filename from path
filename = os.path.basename(icon_path)
if not filename:
return "error:no-filename", ""
dest = os.path.join(out_dir, filename)
if os.path.exists(dest) and os.path.getsize(dest) > 0:
return "exists", filename
url = BASE_URL + icon_path
try:
req = urllib.request.Request(url, headers={"User-Agent": USER_AGENT})
with urllib.request.urlopen(req, timeout=30) as resp:
data = resp.read()
if not data:
return "empty", filename
tmp = dest + ".part"
with open(tmp, "wb") as fh:
fh.write(data)
os.replace(tmp, dest)
return "ok", filename
except urllib.error.HTTPError as e:
if e.code == 404:
return "missing", filename
return f"error:{e.code}", filename
except Exception as e:
return f"error:{repr(e)}", filename
def main():
parser = argparse.ArgumentParser(description="Download all unique marker icon graphics")
parser.add_argument("-m", "--markers-dir", default="../data/markers",
help="Directory containing marker JSON files")
parser.add_argument("-o", "--out-dir", default="../data/icons",
help="Output directory for icons")
parser.add_argument("-w", "--workers", type=int, default=16,
help="Number of concurrent downloads")
args = parser.parse_args()
# Resolve directories relative to script location
script_dir = os.path.dirname(os.path.abspath(__file__))
markers_dir = os.path.join(script_dir, args.markers_dir) if not os.path.isabs(args.markers_dir) else args.markers_dir
out_dir = os.path.join(script_dir, args.out_dir) if not os.path.isabs(args.out_dir) else args.out_dir
# Collect unique icons from all marker files
icon_paths = collect_unique_icons(markers_dir)
if not icon_paths:
print("No icons found. Run extract_all_markers.py first.")
sys.exit(1)
# Create output directory
os.makedirs(out_dir, exist_ok=True)
# Download all icons
print(f"\nDownloading {len(icon_paths)} icons to: {out_dir}")
counts = {"ok": 0, "exists": 0, "missing": 0, "error": 0}
done = 0
t0 = time.time()
with ThreadPoolExecutor(max_workers=args.workers) as pool:
futures = {}
for icon_path in icon_paths:
futures[pool.submit(download_icon, icon_path, out_dir)] = icon_path
for fut in as_completed(futures):
status, filename = fut.result()
kind = status.split(":", 1)[0]
counts[kind] += 1
done += 1
if done % max(1, len(icon_paths) // 10) == 0 or done == len(icon_paths):
rate = done / max(time.time() - t0, 1e-6)
print(f" {done}/{len(icon_paths)} ({rate:.1f}/s) "
f"ok={counts['ok']} cached={counts['exists']} missing={counts['missing']} err={counts['error']}",
flush=True)
elapsed = time.time() - t0
print(f"\nDone in {elapsed:.0f}s: downloaded={counts['ok']} cached={counts['exists']} "
f"missing={counts['missing']} failed={counts['error']}")
print(f"Icons saved to: {out_dir}")
if __name__ == "__main__":
main()