SPB Git

Repository Public

clubautozone.py 8.5 KB 220 lines python

1# =============================================================================2#                  SP BOUCHER | SOFTWARE & RESEARCH3#             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project          : Auto·Ka9# File             : autoka/connectors/clubautozone.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/clubautozone.py : Club Auto Zone (Longueuil) — WordPress sur la91#   plateforme Convertus (thème « achilles » + plugin convertus-vms).92#93#   Stratégie : la page inventaire est une app Vue qui charge les véhicules94#   depuis l'API VMS (vms.prod.convertus.rocks) VIA le proxy PHP du site :95#     /wp-content/plugins/convertus-vms/include/php/ajax-vehicles.php96#         ?endpoint=<URL VMS encodée>&action=vms_data97#   (l'API VMS directe répond 403 ; le proxy du site est la voie officielle).98#   Réponse JSON riche : prix, km, VIN, moteur, couleurs, URL VDP… 30/page.99# -----------------------------------------------------------------------------100from __future__ import annotations101102import urllib.parse103104from ..schema import Vehicle105from .base import BaseConnector106107_VMS_API = "https://vms.prod.convertus.rocks/api/"108_PROXY = "/wp-content/plugins/convertus-vms/include/php/ajax-vehicles.php"109110111def _num(value) -> float | None:112    try:113        v = float(value)114        return v if v > 0 else None115    except (TypeError, ValueError):116        return None117118119class ClubAutoZone(BaseConnector):120    source_id = "clubautozone"121    base_url = "https://www.clubautozone.ca"122    dealer_name = "Club Auto Zone"123    city = "Longueuil"124    inventory_id = 2292              # globalVars.inventoryId du site (cp=…)125    request_delay: float = 1.0126127    def _page(self, pg: int) -> dict:128        endpoint = (f"{_VMS_API}filtering/?cp={self.inventory_id}"129                    f"&ln=fr&sc=used&pg={pg}&pc=100")130        url = (f"{self.base_url}{_PROXY}"131               f"?endpoint={urllib.parse.quote(endpoint, safe='')}"132               f"&action=vms_data")133        return self.get(url).json()134135    def fetch(self) -> list[Vehicle]:136        vehicles: list[Vehicle] = []137        seen: set[str] = set()138        pg = 1139        while pg <= 40:140            data = self._page(pg)141            results = data.get("results") or []142            new = 0143            for d in results:144                veh = self._to_vehicle(d)145                if veh is not None and veh.external_id not in seen:146                    seen.add(veh.external_id)147                    vehicles.append(veh)148                    new += 1149            if not results or new == 0:   # page vide ou déjà tout vu150                break151            pg += 1152        return vehicles153154    def _to_vehicle(self, d: dict) -> Vehicle | None:155        ext_id = str(d.get("vehicle_id") or d.get("ad_id") or "")156        if not ext_id:157            return None158        sale_class = str(d.get("sale_class") or "")159        if sale_class and "occasion" not in sale_class.lower() \160                and "used" not in sale_class.lower():161            return None162163        year = d.get("year") if isinstance(d.get("year"), int) else None164        title = " ".join(str(x) for x in165                         (year, d.get("make"), d.get("model"),166                          d.get("search_trim") or d.get("trim")) if x)167168        price = (_num(d.get("final_price")) or _num(d.get("internet_price"))169                 or _num(d.get("asking_price")))170        km = _num(d.get("odometer"))171172        image = d.get("image") or {}173        images = []174        if isinstance(image, dict) and image.get("image_original") \175                and not d.get("placeholder_image"):176            images = [image["image_original"]]177178        try:179            doors = int(d.get("doors")) or None180        except (TypeError, ValueError):181            doors = None182        try:183            seats = int(d.get("passenger")) or None184        except (TypeError, ValueError):185            seats = None186187        details = {k: d[k] for k in ("days_on_lot", "certified", "cylinder",188                                     "engine_displacement", "vehicle_class")189                   if d.get(k) not in (None, "", 0)}190191        return Vehicle(192            source=self.source_id,193            external_id=ext_id,194            url=str(d.get("vdp_url") or f"{self.base_url}/vehicles/used/"),195            title=title,196            make=str(d.get("make") or ""),197            model=str(d.get("model") or ""),198            trim=str(d.get("search_trim") or d.get("trim") or ""),199            year=year,200            price=price,201            price_label=(f"{price:,.0f} $".replace(",", " ") if price else ""),202            mileage_km=km,203            mileage_label=(f"{km:,.0f} km".replace(",", " ") if km else ""),204            transmission=str(d.get("transmission") or ""),205            fuel=str(d.get("fuel_type") or ""),206            drivetrain=str(d.get("drive_train") or ""),207            body_type=str(d.get("body_style") or ""),208            exterior_color=str(d.get("exterior_color") or ""),209            interior_color=str(d.get("interior_color") or ""),210            engine=str(d.get("engine") or ""),211            doors=doors,212            seats=seats,213            vin=str(d.get("vin") or ""),214            stock_number=str(d.get("stock_number") or ""),215            dealer_name=self.dealer_name,216            city=self.city,217            details=details,218            images=images,219        )220
Files main
Menu

Theme