Download deploy/scripts/prewarm_tiles.py from eduzrh/helloworld: direct link, hf CLI and curl.
- Browser
- Download file 946 Bytes
-
https://huggingface.co/datasets/eduzrh/helloworld/resolve/main/deploy/scripts/prewarm_tiles.py
- Command line
-
hf download hf://datasets/eduzrh/helloworld/deploy/scripts/prewarm_tiles.py
-
curl -L -o prewarm_tiles.py https://huggingface.co/datasets/eduzrh/helloworld/resolve/main/deploy/scripts/prewarm_tiles.py
946 Bytes
| import concurrent.futures as cf | |
| import urllib.request | |
| LAYERS = [ | |
| ("VIIRS_CityLights_2012", "2012-01-01", "GoogleMapsCompatible_Level8", "jpg"), | |
| ("BlueMarble_ShadedRelief_Bathymetry", "500m", "GoogleMapsCompatible_Level8", "jpeg"), | |
| ] | |
| MAXZ = 5 | |
| def urls(): | |
| for layer, date, matrix, ext in LAYERS: | |
| for z in range(MAXZ + 1): | |
| n = 2 ** z | |
| for y in range(n): | |
| for x in range(n): | |
| yield f"http://127.0.0.1/tiles/gibs/{layer}/default/{date}/{matrix}/{z}/{y}/{x}.{ext}" | |
| def fetch(u): | |
| try: | |
| with urllib.request.urlopen(u, timeout=60) as r: | |
| return r.status | |
| except Exception: | |
| return 0 | |
| L = list(urls()) | |
| ok = 0 | |
| with cf.ThreadPoolExecutor(12) as ex: | |
| for i, st in enumerate(ex.map(fetch, L), 1): | |
| ok += 1 if st == 200 else 0 | |
| if i % 200 == 0: | |
| print(i, "/", len(L), "ok", ok, flush=True) | |
| print("done", ok, "/", len(L)) | |