import requests
import os

base_url = 'https://iserver.supermap.io/iserver/services/map-beijing/rest/maps/beijingMap/tileFeature/sdffonts/Open%20Sans%20Regular,Arial%20Unicode%20MS%20Regular/'
filename_template = '{}-{}.pbf'
download_dir = 'E:/work_space/项目文件/wp-fed-mango/code/web/src/components/gis/style/fonts/Open Sans Regular,Arial Unicode MS Regular'

for start in range(0, 65536, 256):
    end = start + 255
    url = base_url + filename_template.format(start, end)
    filename = filename_template.format(start, end)

    response = requests.get(url)

    if response.status_code == 200:
        filepath = os.path.join(download_dir, filename)
        with open(filepath, 'wb') as f:
            f.write(response.content)
            print(f"Downloaded {filename} ({len(response.content)} bytes)")
    else:
        print(
            f"Failed to download {filename} ({response.status_code} {response.reason})")

