fix: Refactor Overpass query to use requests and osmtogeojson for animal shelter data retrieval
This commit is contained in:
		@@ -1,8 +1,8 @@
 | 
				
			|||||||
import argparse
 | 
					import argparse
 | 
				
			||||||
import os
 | 
					import os
 | 
				
			||||||
import requests
 | 
					import requests
 | 
				
			||||||
# TODO: consider using OSMPythonTools instead of overpass
 | 
					# TODO: consider using OSMPythonTools instead of requests or overpass library
 | 
				
			||||||
import overpass
 | 
					from osmtogeojson import osmtogeojson
 | 
				
			||||||
from tqdm import tqdm
 | 
					from tqdm import tqdm
 | 
				
			||||||
 | 
					
 | 
				
			||||||
DEFAULT_OSM_DATA_FILE = "export.geojson"
 | 
					DEFAULT_OSM_DATA_FILE = "export.geojson"
 | 
				
			||||||
@@ -78,14 +78,18 @@ def https(value):
 | 
				
			|||||||
# TODO: take note of new get_overpass_result function which does the bulk of the new overpass query work
 | 
					# TODO: take note of new get_overpass_result function which does the bulk of the new overpass query work
 | 
				
			||||||
def get_overpass_result(area):
 | 
					def get_overpass_result(area):
 | 
				
			||||||
    """Build the Overpass query for fetching animal shelters in the specified area."""
 | 
					    """Build the Overpass query for fetching animal shelters in the specified area."""
 | 
				
			||||||
    api = overpass.API()
 | 
					    overpass_endpoint = "https://overpass-api.de/api/interpreter"
 | 
				
			||||||
    result = api.get(f"""
 | 
					    overpass_query = f"""
 | 
				
			||||||
                     // fetch area to search within
 | 
					        [out:json][timeout:25];
 | 
				
			||||||
        area[name="{area}"]->.searchArea;
 | 
					        area[name="{area}"]->.searchArea;
 | 
				
			||||||
                     // gather results
 | 
					 | 
				
			||||||
        nwr["amenity"="animal_shelter"](area.searchArea);
 | 
					        nwr["amenity"="animal_shelter"](area.searchArea);
 | 
				
			||||||
                     """, verbosity="geom"
 | 
					        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
 | 
					        return result
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user