From f9f35f91049bd8a5634ea53986aa358ff1e713c1 Mon Sep 17 00:00:00 2001 From: moanos Date: Wed, 26 Nov 2025 23:41:03 +0100 Subject: [PATCH] feat: Add exclude shelters with different purpose --- pyproject.toml | 4 ++++ scripts/upload_animal_shelters.py | 25 +++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index c4411b8..2477391 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -58,6 +58,10 @@ docs = [ "sphinx-rtd-theme", "sphinx-autobuild" ] +shelter-upload = [ + "osm2geojson", + "tqdm" +] [project.urls] homepage = "https://notfellchen.org" diff --git a/scripts/upload_animal_shelters.py b/scripts/upload_animal_shelters.py index 63b4052..d762e34 100644 --- a/scripts/upload_animal_shelters.py +++ b/scripts/upload_animal_shelters.py @@ -133,6 +133,19 @@ def get_center_coordinates(geometry): raise ValueError(f"Unsupported geometry type: {geom_type}") +def is_not_for_adoption(tierheim): + """ + Returns true if the shelter is not for the purpose of adoption + """ + if tierheim.purpose_adoption == "no": + return True + elif (tierheim.purpose_adoption is None and + (tierheim.purpose_sanctuary == "yes" or tierheim.purpose_release == "yes")): + return True + else: + return False + + # TODO: take note of new get_overpass_result function which does the bulk of the new overpass query work def get_overpass_result(area, data_file): """Build the Overpass query for fetching animal shelters in the specified area.""" @@ -225,7 +238,13 @@ def main(): description=get_or_none(tierheim, "opening_hours"), external_object_identifier=tierheim["id"], EXTERNAL_SOURCE_IDENTIFIER="OSM", + purpose_adoption=get_or_none(tierheim, "animal_shelter:adoption"), + purpose_sanctuary=get_or_none(tierheim, "animal_shelter:sanctuary"), + purpose_release=get_or_none(tierheim, "animal_shelter:release"), ) + # Skip the shelter if it is not for adopting animals + if is_not_for_adoption(th_data): + continue # Define here for later optional_data = ["email", "phone_number", "website", "description", "fediverse_profile", "facebook", @@ -250,7 +269,8 @@ def main(): result = requests.patch(endpoint, json=org_patch_data, headers=h) if result.status_code != 200: - logging.warning(f"Updating {tierheim['properties']['name']} failed:{result.status_code} {result.json()}") + logging.warning( + f"Updating {tierheim['properties']['name']} failed:{result.status_code} {result.json()}") continue # Rescue organization does not exist else: @@ -268,7 +288,8 @@ def main(): if result.status_code != 201: print(f"{idx} {tierheim["properties"]["name"]}:{result.status_code} {result.json()}") - print(f"Upload finished. Inserted {stats['num_inserted_orgs']} new orgs and updated {stats['num_updated_orgs']} orgs.") + print( + f"Upload finished. Inserted {stats['num_inserted_orgs']} new orgs and updated {stats['num_updated_orgs']} orgs.") if __name__ == "__main__":