SPB Git

Repository Public

scotiabank.py 7.7 KB 191 lines python

1# =============================================================================2#                  SP BOUCHER | SOFTWARE & RESEARCH3#             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project          : Immo·Ka9# File             : immoka/mortgage/providers/scotiabank.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/scotiabank.py : Banque Scotia — API JSON publique91#   dmtsms.scotiabank.com (celle que consomme leur propre page de taux).92#   nonspecialmortgage = taux affichés ; varmortgage = slots promotionnels93#   (le mapping slot -> produit vient de la page ; on ne garde que les slots94#   dont l'identité est connue, avec confiance réduite).95# -----------------------------------------------------------------------------96from __future__ import annotations9798import json99100from .base import RateProvider101102POSTED_URL = "https://dmtsms.scotiabank.com/api/rates/daily/nonspecialmortgage"103PROMO_URL = "https://dmtsms.scotiabank.com/api/rates/daily/varmortgage"104PAGE_URL = ("https://www.scotiabank.com/ca/en/personal/rates-prices/"105            "mortgages-rates.html")106107# PRODUCT -> (rate_type, insured_status, nom, purpose)108POSTED_MAP = {109    "N.H.A. RESIDENTIAL, ETC": ("fixed", "insured", "Fixe affiché (assuré LNH)"),110    "CONVENTIONAL RESIDENTIAL, ETC": ("fixed", "uninsured", "Fixe affiché (conventionnel)"),111    "ULTIMATE VARIABLE RATE": ("variable", "unknown", "Ultimate Variable"),112    "OPEN": ("fixed", "unknown", "Fixe ouvert"),113    "FLEXIBLE": ("fixed", "unknown", "Flexible"),114}115116# Slots promotionnels dont l'identité est documentée sur la page Scotia117# (2026-08). Confiance réduite : si Scotia réordonne ses slots, la validation118# et la comparaison croisée limitent les dégâts.119PROMO_SLOTS = {120    "MORTGAGE PROMOTIONAL 1": ("variable", 60, "Flex Value fermé 5 ans (variable)"),121    "MORTGAGE PROMOTIONAL 2": ("variable", 36, "Ultimate Variable 3 ans"),122    "MORTGAGE PROMOTIONAL 3": ("variable", 60, "Flex Value ouvert 5 ans (variable)"),123}124125126def _term_months(t: dict) -> int | None:127    try:128        v = int(t["TERM_VALUE"])129    except (KeyError, ValueError, TypeError):130        return None131    unit = (t.get("TERM_UNIT") or "").upper()132    if unit == "Y":133        return v * 12134    if unit == "M":135        return v136    return None137138139class ScotiabankProvider(RateProvider):140    provider_id = "scotiabank"141    institution = "Banque Scotia"142    source_url = PAGE_URL143    request_delay = 1.0144145    def fetch(self) -> list[dict]:146        posted = self.get(POSTED_URL).text147        try:148            promo = self.get(PROMO_URL).text149        except Exception:  # noqa: BLE001 — promos facultatives150            promo = ""151        return self.parse(posted) + (self.parse_promos(promo) if promo else [])152153    def parse(self, payload: str) -> list[dict]:154        data = json.loads(payload)155        out: list[dict] = []156        for prod in data.get("data") or []:157            name = (prod.get("PRODUCT") or "").strip()158            if name not in POSTED_MAP:159                continue  # produits chalet/cap/right-rate : hors périmètre160            rtype, insured, label = POSTED_MAP[name]161            for t in prod.get("TERMS") or []:162                term = _term_months(t)163                rate = t.get("RATE")164                if term is None or not isinstance(rate, (int, float)) or rate <= 0:165                    continue166                out.append(self.make_product(167                    rate=float(rate), rate_type=rtype, term_months=term,168                    kind="posted", product_name=label,169                    insured_status=insured,170                    conditions=name,171                    raw={"product": name, "term": t}))172        return out173174    def parse_promos(self, payload: str) -> list[dict]:175        data = json.loads(payload)176        out: list[dict] = []177        for prod in data.get("data") or []:178            name = (prod.get("PRODUCT") or "").strip()179            if name not in PROMO_SLOTS:180                continue181            rate = prod.get("RATE")182            if not isinstance(rate, (int, float)) or rate <= 0:183                continue  # slot inutilisé184            rtype, term, label = PROMO_SLOTS[name]185            out.append(self.make_product(186                rate=float(rate), rate_type=rtype, term_months=term,187                kind="special", product_name=label, confidence=0.8,188                conditions=f"Slot promotionnel Scotia ({name})",189                raw={"product": name, "rate": rate}))190        return out191
Files main
Menu

Theme