Spaces:
Runtime error
Runtime error
Download test_fetch_all.py from KassimYassin/palate: direct link, hf CLI and curl.
- Browser
- Download file 1.09 kB
-
https://huggingface.co/spaces/KassimYassin/palate/resolve/main/test_fetch_all.py
- Command line
-
hf download hf://spaces/KassimYassin/palate/test_fetch_all.py
-
curl -L -o test_fetch_all.py https://huggingface.co/spaces/KassimYassin/palate/resolve/main/test_fetch_all.py
1.09 kB
| import urllib.request | |
| import urllib.parse | |
| import json | |
| import sys | |
| if sys.platform == "win32" and hasattr(sys.stdout, "reconfigure"): | |
| sys.stdout.reconfigure(encoding="utf-8") | |
| query = """ | |
| [out:json][timeout:60]; | |
| area["name"="Amsterdam"]["admin_level"="8"]->.a; | |
| ( | |
| node["amenity"~"restaurant|cafe|fast_food|bar|pub|ice_cream"](area.a); | |
| node["shop"~"bakery|seafood|pastry|deli"](area.a); | |
| way["amenity"~"restaurant|cafe|fast_food|bar|pub|ice_cream"](area.a); | |
| ); | |
| out center; | |
| """ | |
| print("Querying Overpass for complete Amsterdam municipality...") | |
| req = urllib.request.Request( | |
| "https://overpass-api.de/api/interpreter", | |
| data=f"data={urllib.parse.quote(query)}".encode("utf-8"), | |
| headers={"User-Agent": "PalateAmsterdamFullCoverage/1.0"} | |
| ) | |
| try: | |
| with urllib.request.urlopen(req, timeout=90) as resp: | |
| raw = resp.read().decode("utf-8") | |
| data = json.loads(raw) | |
| elements = data.get("elements", []) | |
| print(f"Success! Total elements returned for all Amsterdam: {len(elements)}") | |
| except Exception as e: | |
| print(f"Error querying Overpass: {e}") | |