greggs: add fetch_data
This commit is contained in:
parent
c7fa26fd4c
commit
cff1e79363
1 changed files with 39 additions and 0 deletions
39
greggs.py
Executable file
39
greggs.py
Executable file
|
|
@ -0,0 +1,39 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import overpy
|
||||||
|
|
||||||
|
# brandname : overpass query filters
|
||||||
|
BRANDS: dict[str, str] = {
|
||||||
|
"greggs": "[\"brand:wikidata\"=\"Q3403981\"]",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def fetch_data(brand: str) -> list[tuple[float | None, float | None]]:
|
||||||
|
api = overpy.Overpass()
|
||||||
|
|
||||||
|
filters = BRANDS[brand]
|
||||||
|
query = api.query(f"nwr{filters}; out center;")
|
||||||
|
|
||||||
|
result = []
|
||||||
|
|
||||||
|
for way in query.ways:
|
||||||
|
result.append((way.center_lat, way.center_lon))
|
||||||
|
|
||||||
|
for node in query.nodes:
|
||||||
|
result.append((node.lat, node.lon))
|
||||||
|
|
||||||
|
for (lat, lon) in result:
|
||||||
|
if (lat is None) or (lon is None):
|
||||||
|
raise ValueError("Item missing coords!")
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
print("Running query...")
|
||||||
|
greggs = fetch_data("greggs")
|
||||||
|
print(f"Query done - got {len(greggs)} Greggs!")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue