Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -128,47 +128,40 @@ def search_rescuegroups_pets(params):
|
|
128 |
st.error("⚠️ RescueGroups API key missing. Please set it.")
|
129 |
return []
|
130 |
|
131 |
-
url = "https://api.rescuegroups.org/v5/public/animals/search
|
132 |
|
133 |
headers = {
|
134 |
-
"Authorization":
|
135 |
"Content-Type": "application/vnd.api+json"
|
136 |
}
|
137 |
|
138 |
-
#
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
143 |
}
|
144 |
|
145 |
try:
|
146 |
-
response = requests.
|
147 |
response.raise_for_status()
|
148 |
animals = response.json().get('data', [])
|
149 |
formatted_pets = []
|
150 |
|
151 |
-
# Normalize result
|
152 |
for pet in animals:
|
153 |
-
|
154 |
-
|
155 |
-
'name': pet['attributes']['name'],
|
156 |
-
'status': 'adoptable',
|
157 |
-
'age': pet['attributes']['ageGroup'],
|
158 |
-
'gender': pet['attributes']['sex'],
|
159 |
-
'size': pet['attributes']['size'],
|
160 |
-
'photos': [{'medium': pet['attributes'].get('pictureThumbnailUrl', '')}] if pet['attributes'].get('pictureThumbnailUrl') else [],
|
161 |
-
'description': pet['attributes']['descriptionText'],
|
162 |
-
'breeds': {'primary': pet['attributes']['breedPrimary'], 'secondary': pet['attributes']['breedSecondary'], 'mixed': False},
|
163 |
-
'colors': {'primary': None, 'secondary': None, 'tertiary': None},
|
164 |
-
'contact': {
|
165 |
-
'address': {'city': pet['attributes'].get('locationCity', ''), 'state': pet['attributes'].get('locationState', ''), 'postcode': ''},
|
166 |
-
'email': pet['attributes'].get('contactEmail', ''),
|
167 |
-
'phone': pet['attributes'].get('contactPhone', '')
|
168 |
-
},
|
169 |
-
'organization_id': pet['relationships'].get('orgs', {}).get('data', [{}])[0].get('id', ''),
|
170 |
-
'source': 'RescueGroups'
|
171 |
-
}
|
172 |
formatted_pets.append(formatted_pet)
|
173 |
|
174 |
return formatted_pets
|
|
|
128 |
st.error("⚠️ RescueGroups API key missing. Please set it.")
|
129 |
return []
|
130 |
|
131 |
+
url = "https://api.rescuegroups.org/v5/public/animals/search"
|
132 |
|
133 |
headers = {
|
134 |
+
"Authorization": api_key,
|
135 |
"Content-Type": "application/vnd.api+json"
|
136 |
}
|
137 |
|
138 |
+
# Map species for RescueGroups
|
139 |
+
species = params.get("type", "")
|
140 |
+
mapped_species = RESCUEGROUPS_SPECIES_MAPPING.get(species, "")
|
141 |
+
|
142 |
+
# Fallback: skip call if unsupported
|
143 |
+
if not mapped_species:
|
144 |
+
return []
|
145 |
+
|
146 |
+
payload = {
|
147 |
+
"data": {
|
148 |
+
"filterRadius": {
|
149 |
+
"miles": params.get("distance", 100),
|
150 |
+
"postalcode": params.get("location", "")
|
151 |
+
},
|
152 |
+
"filter": [{"fieldName": "species", "operation": "equals", "criteria": mapped_species}]
|
153 |
+
}
|
154 |
}
|
155 |
|
156 |
try:
|
157 |
+
response = requests.post(url, headers=headers, json=payload)
|
158 |
response.raise_for_status()
|
159 |
animals = response.json().get('data', [])
|
160 |
formatted_pets = []
|
161 |
|
|
|
162 |
for pet in animals:
|
163 |
+
# Normalize pet details
|
164 |
+
formatted_pet = { ... } # your existing normalization
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
165 |
formatted_pets.append(formatted_pet)
|
166 |
|
167 |
return formatted_pets
|