# ----------------------------------------------------------------------------- # Lou-Ka — Location court terme # connectors/chaletsarabais.py : Chalet à Rabais (https://chaletarabais.com) # # ⚠️ Le domaine réel est chaletarabais.com (SANS « s » après chalet) — # chaletsarabais.com listé dans sources_ct.json ne résout plus (SERVFAIL). # # Méthode : WordPress (thème Homey). L'API REST expose le CPT `listing` # (/wp-json/wp/v2/listings) avec taxonomies listing_state / listing_area / # listing_city → inventaire complet paginé + filtre Québec (state `quebec`, # id 614 ; les chalets Ontario sont exclus). La description vient de # content.rendered ; la page détail (cache self.detail, clé = date de # modification WP) fournit lat/lng, grille de prix saisonnière (« 1 nuit »), # voyageurs/lits/salles de bain, chambres, commodités, animaux et photos # (bucket photoschaletarabais.storage.googleapis.com). # ----------------------------------------------------------------------------- from __future__ import annotations import html as _html import re from ..schema import StListing, parse_price_night from .base import StConnector API = "https://chaletarabais.com/wp-json/wp/v2" # slugs listing_area → région touristique canonique Lou-Ka _AREA_REGION = { "abitibi": "Abitibi-Témiscamingue", "bas-saint-laurent": "Bas-Saint-Laurent", "capitale-nationale": "Québec", "centre-du-quebec": "Centre-du-Québec", "charlevoix": "Charlevoix", "chaudiere-appalaches": "Chaudière-Appalaches", "estrie": "Cantons-de-l'Est", "gaspesie": "Gaspésie", "lanaudiere": "Lanaudière", "laurentides": "Laurentides", "mauricie": "Mauricie", "monteregie": "Montérégie", "outaouais": "Outaouais", "saguenay-lac-saint-jean": "Saguenay–Lac-Saint-Jean", } _TAG_RE = re.compile(r"<[^>]+>") def _text(fragment: str) -> str: return _html.unescape(re.sub(r"\s+", " ", _TAG_RE.sub(" ", fragment))).strip() def _num(raw: str) -> float | None: m = re.search(r"\d+(?:[.,]\d+)?", raw or "") return float(m.group(0).replace(",", ".")) if m else None class ChaletsARabais(StConnector): source_id = "chaletsarabais" # -- taxonomies ------------------------------------------------------- def _terms(self, rest_base: str) -> dict[int, dict]: out: dict[int, dict] = {} page = 1 while True: try: resp = self.get(f"{API}/{rest_base}", params={"per_page": 100, "page": page, "_fields": "id,name,slug"}) except Exception: break batch = resp.json() if not isinstance(batch, list) or not batch: break for t in batch: out[t["id"]] = t if len(batch) < 100: break page += 1 return out # -- page détail ------------------------------------------------------ def _detail(self, url: str) -> dict: h = self.get(url).text d: dict = {} m = re.search(r'data-lat="(-?[\d.]+)"', h) m2 = re.search(r'data-long="(-?[\d.]+)"', h) if m and m2: d["lat"], d["lng"] = float(m.group(1)), float(m2.group(1)) #