Repository Public
1# =============================================================================2# SP BOUCHER | SOFTWARE & RESEARCH3# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project : Auto·Ka9# File : autoka/connectors/dupontford.py10# Module : autoka11# Repository : https://git.spboucher.ai/auto-ka12# Created : 2026-08-1213# Last Modified : 2026-08-1214#15# =============================================================================16# AUTHOR & PROFESSIONAL AFFILIATION17# =============================================================================18#19# Author : Simon-Pierre Boucher20# Position : Professor of Finance21# Institution : Université du Québec en Outaouais (UQO)22# Department : Département des sciences administratives23# Organization : SP Boucher24#25# Website : https://spboucher.ai26# Git : https://git.spboucher.ai27#28# =============================================================================29# OFFICIAL CONTACT DIRECTORY30# =============================================================================31#32# General : info@spboucher.ai33# Professional : contact@spboucher.ai34# Direct : simon@spboucher.ai35# Research : research@spboucher.ai36# Development : dev@spboucher.ai37# Support : support@spboucher.ai38# Security/Admin : admin@spboucher.ai39# Notifications : notifications@spboucher.ai40#41# Preferred Contact: contact@spboucher.ai42#43# =============================================================================44# COPYRIGHT & INTELLECTUAL PROPERTY45# =============================================================================46#47# Copyright (c) 202648# Simon-Pierre Boucher49#50# All rights reserved where applicable.51#52# This file is governed by the applicable project license,53# copyright notices, institutional agreements and relevant law.54#55# Unless expressly authorized by the applicable license or56# rights holder, copying, redistribution, sublicensing,57# publication and commercial exploitation are not permitted.58#59# Existing third-party rights and notices remain unaffected.60#61# =============================================================================62# CONFIDENTIALITY & SECURITY63# =============================================================================64#65# Classification : Public66# Distribution : Public repository; use is governed by the project license67# Security Contact : admin@spboucher.ai68#69# Access to this source does not independently grant permission70# to redistribute or disclose confidential materials.71#72# Do not embed credentials, private keys, access tokens,73# certificates or confidential personal information.74#75# =============================================================================76# LICENSE & MAINTENANCE77# =============================================================================78#79# License : None specified (no license file in this repository)80# Maintainer : Simon-Pierre Boucher81# Technical Contact: dev@spboucher.ai82#83# =============================================================================84# END OF SP BOUCHER SOURCE HEADER85# =============================================================================8687# -----------------------------------------------------------------------------88# Auto-Ka — Agrégateur de voitures usagées à vendre (province de Québec)89# Auteur : Simon-Pierre Boucher — contact@spboucher.ai90# connectors/dupontford.py : connecteur Dupont & Dupont Ford91# (dupontdupontford.com), concessionnaire Ford de Gatineau.92#93# Plateforme : WordPress + thème Leadbox « lbx-egypt » (SPA Vue pour94# l'inventaire). Le SPA charge un export JSON statique complet :95# /wp-content/uploads/data/inventory.json -> {"vehicles": [...]} où chaque96# véhicule est COMPLET : condition (New/Used), année, marque, modèle,97# version, prix, km, VIN, stock, transmission, rouage, carburant,98# carrosserie, moteur, couleur, photo, description. UNE seule requête pour99# tout l'inventaire — on filtre condition == Used (voitures seulement).100#101# URL détail reconstruite comme dans le sitemap inventory.xml :102# /vue/used-<année>-<marque>-<modèle>-<id>/.103# -----------------------------------------------------------------------------104from __future__ import annotations105106import html as htmllib107import re108109from ..schema import Vehicle, strip_accents110from .base import BaseConnector111112_EXCLUDE_RE = re.compile(113 r"moto(?:cyclette|neige|marine)?\b|\bvtt\b|scooter|spyder|ryker|"114 r"can-?am|ski-?doo|sea-?doo|roulotte|remorque|\bvr\b|campeur|trailer",115 re.I)116117118def _slug(text: str) -> str:119 t = strip_accents(str(text or "")).lower()120 t = re.sub(r"[^a-z0-9]+", "-", t)121 return t.strip("-")122123124def _clean(text) -> str:125 if not text:126 return ""127 out = htmllib.unescape(str(text))128 out = re.sub(r"<[^>]+>", " ", out)129 return re.sub(r"\s{2,}", " ", out).strip()130131132def _num(value, cast=float):133 try:134 v = cast(value)135 except (TypeError, ValueError):136 return None137 return v if v else None138139140class DupontDupontFord(BaseConnector):141 """Dupont & Dupont Ford — export JSON Leadbox (inventory.json)."""142143 source_id = "dupontdupontford"144 base_url = "https://dupontdupontford.com"145 dealer_name = "Dupont & Dupont Ford"146 city = "Gatineau"147 request_delay = 1.0148 use_detail_cache = False # une seule requête, pas de pages détail149150 def fetch(self) -> list[Vehicle]:151 data = self.get(152 f"{self.base_url}/wp-content/uploads/data/inventory.json").json()153 vehicles: list[Vehicle] = []154 for d in data.get("vehicles") or []:155 veh = self._to_vehicle(d)156 if veh is not None:157 vehicles.append(veh)158 return vehicles159160 def _to_vehicle(self, d: dict) -> Vehicle | None:161 if str(d.get("condition") or "").lower() != "used":162 return None # occasion seulement163 if d.get("nonvehicle") or d.get("onweb") is False:164 return None165 if d.get("salepending") or d.get("sold"):166 return None167 if str(d.get("kind") or "car").lower() != "car":168 return None169170 ext_id = str(d.get("id") or "")171 make = _clean(d.get("make"))172 model = _clean(d.get("model"))173 if not ext_id or not (make or model):174 return None175 body = _clean(d.get("bodystyle") or d.get("type"))176 if _EXCLUDE_RE.search(f"{make} {model} {body}"):177 return None178179 year = _num(d.get("year"), int)180 trim = _clean(d.get("trim"))181 title = " ".join(str(x) for x in (make, model, trim, year or "") if x)182183 url = (f"{self.base_url}/vue/used-{year or ''}-"184 f"{_slug(make)}-{_slug(model)}-{ext_id}/")185186 price = _num(d.get("specialprice")) or _num(d.get("price")) \187 or _num(d.get("saleprice"))188 km = _num(d.get("mileage"))189190 images = []191 if d.get("picture"):192 images = [str(d["picture"])]193 media = d.get("media")194 if isinstance(media, list):195 for u in media:196 if isinstance(u, str) and u not in images:197 images.append(u)198 elif isinstance(u, dict):199 link = u.get("url") or u.get("src")200 if link and link not in images:201 images.append(str(link))202203 details: dict = {}204 for key, out in (("certified", "certified"), ("demo", "demo"),205 ("asis", "as_is")):206 if d.get(key):207 details[out] = True208 if d.get("carprooflink"):209 carfax = str(d["carprooflink"])210 else:211 carfax = ""212 if d.get("rebatesamount"):213 details["rebates"] = d["rebatesamount"]214215 return Vehicle(216 source=self.source_id,217 external_id=ext_id,218 url=url,219 title=title,220 make=make,221 model=model,222 trim=trim,223 year=year,224 price=price,225 price_label=f"{price:,.0f} $".replace(",", " ") if price else "",226 mileage_km=km,227 mileage_label=f"{km:,.0f} km".replace(",", " ") if km else "",228 transmission=_clean(d.get("transmission")),229 fuel=_clean(d.get("fueltype")),230 drivetrain=_clean(d.get("drivetrain")),231 body_type=body,232 exterior_color=_clean(d.get("exteriorcolor")),233 engine=_clean(d.get("engine")),234 seats=_num(d.get("seats"), int),235 vin=_clean(d.get("vin")),236 stock_number=_clean(d.get("stocknumber")),237 dealer_name=self.dealer_name,238 city=self.city,239 description=_clean(d.get("description"))[:4000],240 details=details,241 images=images[:20],242 carfax_url=carfax,243 )244