28 lines
872 B
Python
28 lines
872 B
Python
import json
|
|
from urllib.request import urlopen, Request
|
|
from pathlib import Path
|
|
|
|
ICON_LIST_URL = "https://cc0-icons.jonh.eu/icons.json"
|
|
BASE_URL = "https://cc0-icons.jonh.eu/"
|
|
|
|
OUTPUT_DIR = Path(__file__).resolve().parent.parent / "static" / "icons"
|
|
|
|
|
|
def main() -> None:
|
|
OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
|
|
req = Request(ICON_LIST_URL, headers={"User-Agent": "Mozilla/5.0"})
|
|
with urlopen(req) as resp:
|
|
data = json.load(resp)
|
|
icons = data.get("icons", [])
|
|
for icon in icons:
|
|
slug = icon.get("slug")
|
|
url = BASE_URL + icon.get("url")
|
|
path = OUTPUT_DIR / f"{slug}.svg"
|
|
req = Request(url, headers={"User-Agent": "Mozilla/5.0"})
|
|
with urlopen(req) as resp:
|
|
path.write_bytes(resp.read())
|
|
print(f"Downloaded {len(icons)} icons to {OUTPUT_DIR}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|