helloworld / deploy /scripts /prewarm_tiles.py
eduzrh's picture
Upload deploy/scripts/prewarm_tiles.py with huggingface_hub
9a63005 verified
Raw History Blame Contribute Delete
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))