SPB Git

Repository Public

convertus_fc.py 6.4 KB 171 lines python

1# =============================================================================2#                  SP BOUCHER | SOFTWARE & RESEARCH3#             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project          : Auto·Ka9# File             : autoka/connectors/convertus_fc.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/convertus_fc.py : concessionnaires WordPress « Convertus »91#   (thème achilles) protégés par Cloudflare — accès via Firecrawl.92#93#   Même API VMS que clubautozone.py (proxy officiel du site94#   ajax-vehicles.php -> vms.prod.convertus.rocks), mais chaque appel passe95#   par Firecrawl pour franchir Cloudflare. Le JSON revient enveloppé dans96#   un <body> HTML — on l'extrait puis on réutilise le parseur VMS.97# -----------------------------------------------------------------------------98from __future__ import annotations99100import json101import re102import urllib.parse103104from ..schema import Vehicle105from .clubautozone import ClubAutoZone106107_VMS_API = "https://vms.prod.convertus.rocks/api/"108_PROXY = "/wp-content/plugins/convertus-vms/include/php/ajax-vehicles.php"109110111class ConvertusFirecrawlConnector(ClubAutoZone):112    """Hérite du parseur VMS de ClubAutoZone ; fetch via Firecrawl."""113114    source_id = ""                    # base abstraite : non enregistrée115    inventory_id = 0116117    def _page(self, pg: int) -> dict:118        endpoint = (f"{_VMS_API}filtering/?cp={self.inventory_id}"119                    f"&ln=fr&sc=used&pg={pg}&pc=100")120        url = (f"{self.base_url}{_PROXY}"121               f"?endpoint={urllib.parse.quote(endpoint, safe='')}"122               f"&action=vms_data")123        html = self.get_rendered(url)124        # le JSON est enveloppé dans <body>…</body> par le rendu Firecrawl125        m = re.search(r"<body[^>]*>(.*)</body>", html, re.S)126        payload = (m.group(1) if m else html).strip()127        try:128            return json.loads(payload)129        except ValueError:130            return {}131132    def _resolve_inventory_id(self) -> None:133        """Lit globalVars.inventoryId sur la page inventaire si inconnu."""134        if self.inventory_id:135            return136        html = self.get_rendered(f"{self.base_url}/vehicles/used/")137        m = re.search(r'inventoryId"\s*:\s*"?(\d+)', html)138        if not m:139            raise RuntimeError("inventoryId introuvable")140        self.inventory_id = int(m.group(1))141142    def fetch(self) -> list[Vehicle]:143        if not self.source_id:144            return []145        self._resolve_inventory_id()146        return super().fetch()147148149class BernieresAuto(ConvertusFirecrawlConnector):150    source_id = "bernieresauto"151    base_url = "https://www.bernieresauto.com"152    dealer_name = "Bernières Auto"153    city = "Saint-Nicolas"154    inventory_id = 1305155156157class AutoFlash(ConvertusFirecrawlConnector):158    source_id = "autoflash"159    base_url = "https://www.autoflash.net"160    dealer_name = "AutoFlash"161    city = "Saint-Hubert"162    inventory_id = 1306163164165class ComplexeAutoPlus(ConvertusFirecrawlConnector):166    source_id = "complexeautoplus"167    base_url = "https://www.complexeautoplus.com"168    dealer_name = "Complexe Auto Plus"169    city = "Saint-Jérôme"170    inventory_id = 855171
Files main
Menu

Theme