SPB Git

Repository Public

demenageurs.py 5.7 KB 146 lines python

1#!/usr/bin/env python32# =============================================================================3#                  SP BOUCHER | SOFTWARE & RESEARCH4#             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5# =============================================================================6#7# PROJECT METADATA8# -----------------------------------------------------------------------------9# Project          : Lou·Ka10# File             : louka/demenageurs.py11# Module           : louka12# Repository       : https://git.spboucher.ai/lou-ka13# Created          : 2026-08-2414# Last Modified    : 2026-08-2415#16# =============================================================================17# AUTHOR & PROFESSIONAL AFFILIATION18# =============================================================================19#20# Author           : Simon-Pierre Boucher21# Position         : Professor of Finance22# Institution      : Université du Québec en Outaouais (UQO)23# Department       : Département des sciences administratives24# Organization     : SP Boucher25#26# Website          : https://spboucher.ai27# Git              : https://git.spboucher.ai28#29# =============================================================================30# OFFICIAL CONTACT DIRECTORY31# =============================================================================32#33# General          : info@spboucher.ai34# Professional     : contact@spboucher.ai35# Direct           : simon@spboucher.ai36# Research         : research@spboucher.ai37# Development      : dev@spboucher.ai38# Support          : support@spboucher.ai39# Security/Admin   : admin@spboucher.ai40# Notifications    : notifications@spboucher.ai41#42# Preferred Contact: contact@spboucher.ai43#44# =============================================================================45# COPYRIGHT & INTELLECTUAL PROPERTY46# =============================================================================47#48# Copyright (c) 202649# Simon-Pierre Boucher50#51# All rights reserved where applicable.52#53# This file is governed by the applicable project license,54# copyright notices, institutional agreements and relevant law.55#56# Unless expressly authorized by the applicable license or57# rights holder, copying, redistribution, sublicensing,58# publication and commercial exploitation are not permitted.59#60# Existing third-party rights and notices remain unaffected.61#62# =============================================================================63# CONFIDENTIALITY & SECURITY64# =============================================================================65#66# Classification   : Public67# Distribution     : Public repository; use is governed by the project license68# Security Contact : admin@spboucher.ai69#70# Access to this source does not independently grant permission71# to redistribute or disclose confidential materials.72#73# Do not embed credentials, private keys, access tokens,74# certificates or confidential personal information.75#76# =============================================================================77# LICENSE & MAINTENANCE78# =============================================================================79#80# License          : None specified (no license file in this repository)81# Maintainer       : Simon-Pierre Boucher82# Technical Contact: dev@spboucher.ai83#84# =============================================================================85# END OF SP BOUCHER SOURCE HEADER86# =============================================================================8788# -----------------------------------------------------------------------------89# Groupe KA — Annuaire des déménageurs du Québec (module partagé Lou-Ka/Immo-Ka)90# demenageurs.py : sert data/demenageurs.json — 565+ entreprises de déménagement91# couvrant les 17 régions administratives (balayage Google Places via Serper).92# Régénération du dataset : scripts/build_demenageurs.py puis remplacer le JSON93# (identique sur Lou-Ka et Immo-Ka — garder les deux copies synchronisées).94# -----------------------------------------------------------------------------95from __future__ import annotations9697import json98import threading99from pathlib import Path100101from fastapi import APIRouter102103ROOT = Path(__file__).resolve().parent.parent104DATA = ROOT / "data" / "demenageurs.json"105106router = APIRouter()107_cache: dict = {"mtime": None, "doc": None}108_lock = threading.Lock()109110111def load() -> dict:112    """Charge (avec cache par mtime) l'annuaire canonique des déménageurs."""113    try:114        mtime = DATA.stat().st_mtime115    except FileNotFoundError:116        return {"generated": None, "count": 0, "movers": [], "regions": []}117    with _lock:118        if _cache["doc"] is None or mtime != _cache["mtime"]:119            doc = json.loads(DATA.read_text(encoding="utf-8"))120            regs: dict[str, int] = {}121            for m in doc.get("movers", []):122                regs[m["region"]] = regs.get(m["region"], 0) + 1123            doc["regions"] = [{"region": r, "n": n}124                              for r, n in sorted(regs.items(),125                                                 key=lambda x: (-x[1], x[0]))]126            _cache["doc"], _cache["mtime"] = doc, mtime127        return _cache["doc"]128129130@router.get("/api/demenageurs")131def api_demenageurs(region: str | None = None, q: str | None = None):132    """Annuaire complet des déménageurs du Québec (filtres : région, texte)."""133    doc = load()134    movers = doc.get("movers", [])135    if region:136        movers = [m for m in movers if m["region"] == region]137    if q:138        needle = q.strip().lower()139        movers = [m for m in movers140                  if needle in (m["name"] + " " + m["city"]).lower()]141    return {"generated": doc.get("generated"),142            "total": doc.get("count", 0),143            "count": len(movers),144            "regions": doc.get("regions", []),145            "movers": movers}146
Files main
Menu

Theme