Repository Public
1#!/usr/bin/env python32# =============================================================================3# SP BOUCHER | SOFTWARE & RESEARCH4# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5# =============================================================================6#7# PROJECT METADATA8# -----------------------------------------------------------------------------9# Project : Immo·Ka10# File : run.py11# Repository : https://git.spboucher.ai/immo-ka12# Created : 2026-08-1213# Last Modified : 2026-08-2514#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# run.py : point d'entrée — `sync`, `watch`, `serve`91# -----------------------------------------------------------------------------92"""Utilisation :93 python run.py sync [source ...] # synchronise les propriétés94 python run.py watch [minutes] # synchronise en boucle (défaut 60 min)95 python run.py serve [port] # démarre l'API + le frontend (défaut 8090)96 python run.py list # liste les connecteurs enregistrés97 python run.py geocode [n] # géocode les annonces sans coordonnées (max n requêtes)98 python run.py geocode-audit [n] [dry] # audit coordonnées <-> ville (n = budget Nominatim)99 python run.py poi [n] # commodités de proximité par immeuble (max n requêtes)100 python run.py quartier [n] # rattache chaque annonce à son aire de diffusion (DAUID)101 python run.py mortgage-sync [slug…] # collecte les taux hypothécaires (toutes banques ou celles listées)102 python run.py mortgage-watch [min] # collecte en boucle (défaut IMMOKA_MORTGAGE_INTERVAL_MIN=180)103 python run.py mortgage-status # santé des providers de taux (OK/WARNING/ERROR)104"""105from __future__ import annotations106107import os108import sys109from pathlib import Path110111# Charger .env (FIRECRAWL_API_KEY, etc.) sans dépendance externe112_env = Path(__file__).parent / ".env"113if _env.exists():114 for line in _env.read_text().splitlines():115 line = line.strip()116 if line and not line.startswith("#") and "=" in line:117 k, _, v = line.partition("=")118 os.environ.setdefault(k.strip(), v.strip())119120121def main() -> None:122 cmd = sys.argv[1] if len(sys.argv) > 1 else "serve"123 if cmd == "sync":124 from immoka import ingest125 ingest.run(sys.argv[2:] or None)126 elif cmd == "watch":127 from immoka import ingest128 minutes = int(sys.argv[2]) if len(sys.argv) > 2 else 60129 ingest.watch(minutes * 60)130 elif cmd == "list":131 from immoka.connectors import CONNECTORS132 for sid in sorted(CONNECTORS):133 print(sid)134 print(f"-- {len(CONNECTORS)} connecteur(s)")135 elif cmd == "geocode":136 from immoka import geocode137 geocode.run_batch(int(sys.argv[2]) if len(sys.argv) > 2 else None)138 elif cmd == "geocode1": # ancien mode 1-par-1 (+ repli Nominatim)139 from immoka import geocode140 geocode.run(int(sys.argv[2]) if len(sys.argv) > 2 else None)141 elif cmd == "geocode-audit": # cohérence coordonnées <-> ville annoncée142 from immoka import geocode143 budget = next((int(a) for a in sys.argv[2:] if a.isdigit()), None)144 geocode.run_audit(nominatim_budget=budget,145 apply="dry" not in sys.argv[2:])146 elif cmd == "poi":147 from immoka import poi148 poi.run(int(sys.argv[2]) if len(sys.argv) > 2 else None)149 elif cmd == "air-refresh":150 from immoka import air151 air.refresh()152 elif cmd == "gaz-refresh":153 from immoka import gaz154 print(f"[gaz] {gaz.refresh()} stations")155 elif cmd == "hydro-precompute":156 from immoka import hydro157 n = int(sys.argv[2]) if len(sys.argv) > 2 else 100158 b = int(sys.argv[3]) if len(sys.argv) > 3 else 40159 hydro.precompute(limit=n, budget=b)160 elif cmd == "inondation-build":161 from immoka import inondation162 inondation.build()163 elif cmd == "quartier":164 from immoka import quartier165 quartier.enrich(int(sys.argv[2]) if len(sys.argv) > 2 else None)166 elif cmd == "vraiprix":167 from immoka import vraiprix168 vraiprix.run(int(sys.argv[2]) if len(sys.argv) > 2 else None)169 elif cmd == "vraiprix_local": # appariement local (vraiprix.db) : rapide170 from immoka import vraiprix_local171 reval = "reval" in sys.argv[2:]172 lim = next((int(a) for a in sys.argv[2:] if a.isdigit()), None)173 if "role" in sys.argv[2:]: # backfill rôle d'évaluation (jointure par id)174 vraiprix_local.enrich_role(lim)175 else:176 vraiprix_local.run(lim, revalidate=reval)177 elif cmd == "mortgage-sync":178 from immoka.mortgage import scheduler179 scheduler.run(sys.argv[2:] or None)180 elif cmd == "mortgage-watch":181 from immoka.mortgage import scheduler182 minutes = int(sys.argv[2]) if len(sys.argv) > 2 else None183 scheduler.watch(minutes)184 elif cmd == "mortgage-status":185 from immoka.mortgage import store186 con = store.connect()187 for h in store.provider_health(con):188 print(f"{h['level']:8s} {h['provider']:15s} "189 f"statut={h.get('status') or '-'} "190 f"produits_courants={h.get('current_products', 0)} "191 f"dernière_passe=il y a {h.get('age_minutes', '?')} min")192 elif cmd == "serve":193 import uvicorn194 port = int(sys.argv[2]) if len(sys.argv) > 2 else 8090195 uvicorn.run("immoka.web:app", host="0.0.0.0", port=port)196 else:197 print(__doc__)198 sys.exit(1)199200201if __name__ == "__main__":202 main()203