File size: 946 Bytes
9a63005
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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))