From c968b3965722566689141b0edbc4b1da675795f9 Mon Sep 17 00:00:00 2001 From: Patrick Moore Date: Wed, 18 Jun 2025 07:07:25 -0400 Subject: [PATCH] fix: Refactor Overpass query to use requests and osmtogeojson for animal shelter data retrieval --- scripts/upload_animal_shelters.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/scripts/upload_animal_shelters.py b/scripts/upload_animal_shelters.py index e2adfaa..41c2a79 100644 --- a/scripts/upload_animal_shelters.py +++ b/scripts/upload_animal_shelters.py @@ -1,8 +1,8 @@ import argparse import os import requests -# TODO: consider using OSMPythonTools instead of overpass -import overpass +# TODO: consider using OSMPythonTools instead of requests or overpass library +from osmtogeojson import osmtogeojson from tqdm import tqdm DEFAULT_OSM_DATA_FILE = "export.geojson" @@ -78,15 +78,19 @@ def https(value): # TODO: take note of new get_overpass_result function which does the bulk of the new overpass query work def get_overpass_result(area): """Build the Overpass query for fetching animal shelters in the specified area.""" - api = overpass.API() - result = api.get(f""" - // fetch area to search within - area[name="{area}"]->.searchArea; - // gather results - nwr["amenity"="animal_shelter"](area.searchArea); - """, verbosity="geom" - ) - return result + overpass_endpoint = "https://overpass-api.de/api/interpreter" + overpass_query = f""" + [out:json][timeout:25]; + area[name="{area}"]->.searchArea; + nwr["amenity"="animal_shelter"](area.searchArea); + out body; + >; + out skel qt; + """ + r = requests.get(overpass_endpoint, params={'data': overpass_query}) + if r.status_code == 200: + result = osmtogeojson.process_osm_json(r.json()) + return result def main():