Use pasted Booking.com search URL to pin scrape destination

The location_search_url column existed but was dead — the scraper always
rebuilt the URL from the free-text location name. Now the Location
Configuration form takes a "Booking.com search URL" field: paste the
address-bar URL from a real search and the scraper lifts ss/dest_id/
dest_type from it (the most reliable destination pin). Falls back to
dest_id, then plain name. Server also extracts dest_id from the URL for
the column and derives a display name from ss when none is typed.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
jtricerolph 2026-07-05 22:00:28 +00:00
parent 9e5728efb1
commit 579a189cb8
5 changed files with 97 additions and 24 deletions

View file

@ -27,10 +27,11 @@ class ScrapeRequest(BaseModel):
class LocationConfigRequest(BaseModel):
location_name: str
location_name: str = ''
pages_to_scrape: int = 2
adults: int = 2
dest_id: Optional[str] = None # Booking.com numeric destination id (pins the search)
location_search_url: Optional[str] = None # Pasted Booking.com search URL (pins destination)
class HotelTierUpdate(BaseModel):
@ -303,6 +304,19 @@ async def set_location_config(
current_user: dict = Depends(get_current_user)
):
"""Set the location to scrape for competitor rates."""
from services.scraper_backends.playwright_local import location_params_from_url
# If a full search URL was pasted, lift the destination params out of it —
# dest_id for the column (visibility/fallback), and ss for the display name
# when the user didn't type one.
search_url = (config.location_search_url or '').strip() or None
url_params = location_params_from_url(search_url) if search_url else {}
dest_id = config.dest_id or url_params.get('dest_id')
location_name = config.location_name.strip() or url_params.get('ss', '')
if not location_name:
raise HTTPException(status_code=400, detail="Provide a location name or a search URL.")
# Deactivate existing configs
await db.execute(
text("UPDATE booking_scrape_config SET is_active = FALSE")
@ -311,15 +325,16 @@ async def set_location_config(
# Insert new config
await db.execute(
text("""
INSERT INTO booking_scrape_config (location_name, pages_to_scrape, adults, dest_id, is_active)
VALUES (:location, :pages, :adults, :dest_id, TRUE)
INSERT INTO booking_scrape_config
(location_name, pages_to_scrape, adults, dest_id, location_search_url, is_active)
VALUES (:location, :pages, :adults, :dest_id, :search_url, TRUE)
"""),
{'location': config.location_name, 'pages': config.pages_to_scrape,
'adults': config.adults, 'dest_id': config.dest_id}
{'location': location_name, 'pages': config.pages_to_scrape,
'adults': config.adults, 'dest_id': dest_id, 'search_url': search_url}
)
await db.commit()
return {"status": "success", "location": config.location_name}
return {"status": "success", "location": location_name}
@router.post("/config/enable")