Repository Public
1# =============================================================================2# SP BOUCHER | SOFTWARE & RESEARCH3# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project : Immo·Ka9# File : immoka/mortgage/providers/desjardins.py10# Module : immoka11# Repository : https://git.spboucher.ai/immo-ka12# Created : 2026-08-2413# Last Modified : 2026-08-2414#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# Immo-Ka — Agrégateur de maisons à vendre (province de Québec)89# Auteur : Simon-Pierre Boucher — contact@spboucher.ai90# mortgage/providers/desjardins.py : Desjardins — JSON server-rendered91# window.dcomProducts sur la page des taux. Clé = cfPath COMPLET (le même92# id existe dans les familles « taux-hypothecaires » (affichés) et93# « taux-hypothecaires-promotionnels » (spéciaux) avec des valeurs94# différentes — ne jamais confondre).95# -----------------------------------------------------------------------------96from __future__ import annotations9798import json99import re100101from .base import RateProvider102103PAGE_URL = "https://www.desjardins.com/fr/hypotheque/taux-hypothecaires.html"104105# id Desjardins -> (rate_type, terme mois, nom, purpose)106ID_MAP: dict[str, tuple] = {107 "6000_6M": ("fixed", 6, "Fixe fermé 6 mois"),108 "6000_1A": ("fixed", 12, "Fixe fermé 1 an"),109 "6000_2A": ("fixed", 24, "Fixe fermé 2 ans"),110 "6000_3A": ("fixed", 36, "Fixe fermé 3 ans"),111 "6000_4A": ("fixed", 48, "Fixe fermé 4 ans"),112 "6000_5A": ("fixed", 60, "Fixe fermé 5 ans"),113 "6000_6A": ("fixed", 72, "Fixe fermé 6 ans"),114 "6000_7A": ("fixed", 84, "Fixe fermé 7 ans"),115 "6000_10A": ("fixed", 120, "Fixe fermé 10 ans"),116 "6000_6MO": ("fixed", 6, "Fixe ouvert 6 mois"),117 "6000_1AO": ("fixed", 12, "Fixe ouvert 1 an"),118 "6004_5AR": ("variable", 60, "Variable réduit 5 ans"),119 "tvp": ("variable", 60, "Variable protégé 5 ans"),120 "tvred": ("variable", 60, "Variable réduit"),121 "tvreg": ("variable", 60, "Variable régulier"),122 "tra": ("fixed", 12, "Révisable annuellement"),123}124PRIME_ID = "tpcad"125126127class DesjardinsProvider(RateProvider):128 provider_id = "desjardins"129 institution = "Desjardins"130 source_url = PAGE_URL131 request_delay = 1.5132133 def fetch(self) -> list[dict]:134 return self.parse(self.get(self.source_url).text)135136 def parse(self, payload: str) -> list[dict]:137 m = re.search(r"window\.dcomProducts\s*=\s*(\{.*?\});", payload, re.S)138 if not m:139 raise ValueError("dcomProducts introuvable (structure changée)")140 products = json.loads(m.group(1))141 out: list[dict] = []142 for cf_path, cell in products.items():143 if "/hypotheque/" not in cf_path or not isinstance(cell, dict):144 continue145 pid = cell.get("id") or ""146 try:147 rate = float(cell.get("rate"))148 except (TypeError, ValueError):149 continue150 if rate <= 0:151 continue152 promo = "taux-hypothecaires-promotionnels" in cf_path153 if pid == PRIME_ID:154 out.append(self.make_product(155 rate=rate, rate_type="other", term_months=12,156 kind="posted", product_name="Taux préférentiel Desjardins",157 purpose="unknown", raw={"cfPath": cf_path, "rate": rate}))158 continue159 if pid not in ID_MAP:160 continue # id inconnu : jamais deviné161 rtype, term, label = ID_MAP[pid]162 out.append(self.make_product(163 rate=rate, rate_type=rtype, term_months=term,164 kind="special" if promo else "posted",165 product_name=label + (" (promotion)" if promo else ""),166 conditions="Taux promotionnel Desjardins" if promo167 else "Taux affiché Desjardins",168 raw={"cfPath": cf_path, "id": pid, "rate": cell.get("rate")}))169 return out170