CCockrum commited on
Commit
2547b7f
·
verified ·
1 Parent(s): 9fb3e09

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -72
app.py CHANGED
@@ -121,54 +121,6 @@ def search_pets(params):
121
  st.error(f"⚠️ Error searching pets: {str(e)}")
122
  return None
123
 
124
- # Function to search pets from RescueGroups.org
125
- def search_rescuegroups_pets(params):
126
- api_key = os.environ.get('RESCUEGROUPS_API_KEY') or st.secrets.get('RESCUEGROUPS_API_KEY')
127
- if not api_key:
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
168
-
169
- except requests.exceptions.RequestException as e:
170
- st.error(f"⚠️ Error searching RescueGroups pets: {str(e)}")
171
- return []
172
 
173
 
174
  # Function to get breeds
@@ -249,9 +201,6 @@ def display_pet_card(pet, is_favorite=False, context="search"):
249
  tags_html += f"<span class='tag'>{pet['gender']}</span> "
250
  if pet['size']:
251
  tags_html += f"<span class='tag'>{pet['size']}</span> "
252
- # Attribution source tag
253
- if 'source' in pet:
254
- st.markdown(f"<span class='tag' style='background-color: #444;'>Source: {pet['source']}</span>", unsafe_allow_html=True)
255
 
256
  st.markdown(f"<div>{tags_html}</div>", unsafe_allow_html=True)
257
 
@@ -470,10 +419,7 @@ def display_pet_card(pet, is_favorite=False, context="search", tab_id="tab1"):
470
  tags_html += f"<span class='tag'>{pet['gender']}</span> "
471
  if pet['size']:
472
  tags_html += f"<span class='tag'>{pet['size']}</span> "
473
- # Attribution source tag
474
- if 'source' in pet:
475
- st.markdown(f"<span class='tag' style='background-color: #444;'>Source: {pet['source']}</span>", unsafe_allow_html=True)
476
-
477
  st.markdown(f"<div>{tags_html}</div>", unsafe_allow_html=True)
478
 
479
  st.markdown("<div class='pet-details'>", unsafe_allow_html=True)
@@ -593,26 +539,13 @@ def main():
593
 
594
  # Perform search
595
  results = search_pets(params)
596
- combined_results = []
597
-
598
  if results and 'animals' in results:
599
- pf_pets = results['animals']
600
- # Add source attribution
601
- for pet in pf_pets:
602
- pet['source'] = 'PetFinder'
603
- combined_results.extend(pf_pets)
604
-
605
- # Fetch from RescueGroups
606
- rg_pets = search_rescuegroups_pets(params)
607
- combined_results.extend(rg_pets)
608
-
609
- if combined_results:
610
- st.session_state.search_results = {'animals': combined_results}
611
  st.session_state.page = 1
612
- st.success(f"Found {len(combined_results)} pets from PetFinder and RescueGroups!")
613
  else:
614
- st.error("No pets found with those criteria.")
615
-
616
  # Display search results
617
  if st.session_state.search_results and 'animals' in st.session_state.search_results:
618
  st.markdown("### Search Results")
 
121
  st.error(f"⚠️ Error searching pets: {str(e)}")
122
  return None
123
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
124
 
125
 
126
  # Function to get breeds
 
201
  tags_html += f"<span class='tag'>{pet['gender']}</span> "
202
  if pet['size']:
203
  tags_html += f"<span class='tag'>{pet['size']}</span> "
 
 
 
204
 
205
  st.markdown(f"<div>{tags_html}</div>", unsafe_allow_html=True)
206
 
 
419
  tags_html += f"<span class='tag'>{pet['gender']}</span> "
420
  if pet['size']:
421
  tags_html += f"<span class='tag'>{pet['size']}</span> "
422
+
 
 
 
423
  st.markdown(f"<div>{tags_html}</div>", unsafe_allow_html=True)
424
 
425
  st.markdown("<div class='pet-details'>", unsafe_allow_html=True)
 
539
 
540
  # Perform search
541
  results = search_pets(params)
 
 
542
  if results and 'animals' in results:
543
+ st.session_state.search_results = results
 
 
 
 
 
 
 
 
 
 
 
544
  st.session_state.page = 1
545
+ st.success(f"Found {len(results['animals'])} pets!")
546
  else:
547
+ st.error("No pets found with those criteria. Try expanding your search.")
548
+
549
  # Display search results
550
  if st.session_state.search_results and 'animals' in st.session_state.search_results:
551
  st.markdown("### Search Results")