Repository Public
1#!/usr/bin/env python32# =============================================================================3# SP BOUCHER | SOFTWARE & RESEARCH4# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5# =============================================================================6#7# PROJECT METADATA8# -----------------------------------------------------------------------------9# Project : FB Ka Automation10# File : assets/make_carousels.py11# Description : Carrousels FB « stats avancées » — 4 sites × 5 cartes,12# couleurs officielles.13# Module : assets14# Repository : https://git.spboucher.ai/fb-ka-automation15# Created : 2026-12-0116# Last Modified : 2026-12-0117#18# =============================================================================19# AUTHOR & PROFESSIONAL AFFILIATION20# =============================================================================21#22# Author : Simon-Pierre Boucher23# Position : Professor of Finance24# Institution : Université du Québec en Outaouais (UQO)25# Department : Département des sciences administratives26# Organization : SP Boucher27#28# Website : https://spboucher.ai29# Git : https://git.spboucher.ai30#31# =============================================================================32# OFFICIAL CONTACT DIRECTORY33# =============================================================================34#35# General : info@spboucher.ai36# Professional : contact@spboucher.ai37# Direct : simon@spboucher.ai38# Research : research@spboucher.ai39# Development : dev@spboucher.ai40# Support : support@spboucher.ai41# Security/Admin : admin@spboucher.ai42# Notifications : notifications@spboucher.ai43#44# Preferred Contact: contact@spboucher.ai45#46# =============================================================================47# COPYRIGHT & INTELLECTUAL PROPERTY48# =============================================================================49#50# Copyright (c) 202651# Simon-Pierre Boucher52#53# All rights reserved where applicable.54#55# This file is governed by the applicable project license,56# copyright notices, institutional agreements and relevant law.57#58# Unless expressly authorized by the applicable license or59# rights holder, copying, redistribution, sublicensing,60# publication and commercial exploitation are not permitted.61#62# Existing third-party rights and notices remain unaffected.63#64# =============================================================================65# CONFIDENTIALITY & SECURITY66# =============================================================================67#68# Classification : Public69# Distribution : Public repository; use is governed by the project license70# Security Contact : admin@spboucher.ai71#72# Access to this source does not independently grant permission73# to redistribute or disclose confidential materials.74#75# Do not embed credentials, private keys, access tokens,76# certificates or confidential personal information.77#78# =============================================================================79# LICENSE & MAINTENANCE80# =============================================================================81#82# License : None specified (no license file in this repository)83# Maintainer : Simon-Pierre Boucher84# Technical Contact: dev@spboucher.ai85#86# =============================================================================87# END OF SP BOUCHER SOURCE HEADER88# =============================================================================8990"""Carrousels FB « stats avancées » — 4 sites × 5 cartes, couleurs officielles.9192Lou-Ka #ff6a00 · Immo-Ka #e23744 · Food-Ka #1f9d55 · Fabri-Ka #c4532e93(accents lus dans styles.css des repos — surcharges officielles ka-ui).94Cartes 1080×1350, surfaces alternées charbon/soft, étiquettes directes,95stats live du 2026-08-22.96"""97import os98from PIL import Image, ImageDraw, ImageFont99100CHARCOAL = (20, 24, 20)101CREAM = (242, 241, 234)102GRAY_D = (150, 156, 148) # texte secondaire sur sombre103TRACK_D = (34, 40, 34)104RING_D = (46, 54, 46)105106BLACK_F = "/System/Library/Fonts/Supplemental/Arial Black.ttf"107BOLD_F = "/System/Library/Fonts/Supplemental/Arial Bold.ttf"108MONO_F = "/System/Library/Fonts/Supplemental/Courier New Bold.ttf"109110W, H = 1080, 1350111BASE = os.path.dirname(os.path.abspath(__file__))112OUT = os.path.join(BASE, "carousels")113114SITES = {115 "lou-ka": dict(name="Lou·Ka", accent=(255, 106, 0), deep=(204, 85, 0),116 soft=(255, 241, 230), url="www.lou-ka.com"),117 "immo-ka": dict(name="Immo·Ka", accent=(226, 55, 68), deep=(168, 35, 46),118 soft=(251, 224, 226), url="www.immo-ka.com"),119 "food-ka": dict(name="Food·Ka", accent=(31, 157, 85), deep=(21, 122, 64),120 soft=(226, 245, 234), url="www.food-ka.com"),121 "fabri-ka": dict(name="Fabri·Ka", accent=(196, 83, 46), deep=(154, 63, 33),122 soft=(247, 227, 218), url="www.fabri-ka.com"),123}124125126def f(p, s):127 return ImageFont.truetype(p, s)128129130def mix(a, b, t):131 return tuple(int(a[i] + (b[i] - a[i]) * t) for i in range(3))132133134def theme(site, dark):135 s = SITES[site]136 if dark:137 return dict(bg=CHARCOAL, ink=CREAM, sub=GRAY_D, bar=s["accent"],138 track=TRACK_D, ring=RING_D, hero=s["accent"],139 ban_fill=s["accent"], ban_ink=CHARCOAL)140 return dict(bg=s["soft"], ink=CHARCOAL, sub=mix(CHARCOAL, s["soft"], 0.45),141 bar=s["deep"], track=mix(s["soft"], CHARCOAL, 0.10),142 ring=mix(s["soft"], CHARCOAL, 0.22), hero=s["deep"],143 ban_fill=CHARCOAL, ban_ink=s["accent"])144145146def fit_font(d, text, path, size, max_w, floor=36):147 while size > floor:148 fo = f(path, size)149 if d.textlength(text, font=fo) <= max_w:150 return fo151 size -= 4152 return f(path, size)153154155def header(d, img, site, t, title, subtitle, idx):156 s = SITES[site]157 d.line([64, 88, 112, 88], fill=t["hero"], width=6)158 d.text((130, 88), f"{s['name'].upper()} · STATS AVANCÉES · 22 AOÛT 2026",159 font=f(BOLD_F, 26), fill=t["hero"], anchor="lm")160 d.text((W - 64, 88), f"{idx}/5", font=f(BLACK_F, 30), fill=t["sub"], anchor="rm")161 # titre162 tf = fit_font(d, title, BLACK_F, 78, W - 128, floor=48)163 d.text((64, 150), title, font=tf, fill=t["ink"])164 if subtitle:165 d.text((66, 160 + tf.size + 26), subtitle, font=f(BOLD_F, 31), fill=t["sub"])166167168def banner(d, site, t):169 d.rounded_rectangle([16, 1246, W - 16, H - 16], radius=26, fill=t["ban_fill"])170 d.text((64, 1290), SITES[site]["url"], font=f(MONO_F, 40), fill=t["ban_ink"], anchor="lm")171 d.text((W - 64, 1290), "GROUPE ·KA", font=f(BLACK_F, 34), fill=t["ban_ink"], anchor="rm")172173174def new_card(site, dark):175 t = theme(site, dark)176 img = Image.new("RGB", (W, H), t["bg"])177 d = ImageDraw.Draw(img)178 d.rounded_rectangle([16, 16, W - 16, H - 16], radius=26, outline=t["ring"], width=3)179 return img, d, t180181182def card_hero(site, dark, title, subtitle, hero, hero_label, tiles, idx):183 img, d, t = new_card(site, dark)184 header(d, img, site, t, title, subtitle, idx)185 hf = fit_font(d, hero, BLACK_F, 190, W - 128)186 d.text((60, 430), hero, font=hf, fill=t["hero"])187 d.text((66, 430 + hf.size + 56), hero_label, font=f(BOLD_F, 42), fill=t["ink"])188 ty = 800189 d.line([64, ty - 30, W - 64, ty - 30], fill=t["ring"], width=2)190 col = (W - 128) / len(tiles)191 for i, (val, lab) in enumerate(tiles):192 x = 64 + int(i * col)193 vf = fit_font(d, val, BLACK_F, 56, col - 26)194 d.text((x, ty), val, font=vf, fill=t["ink"])195 lf = f(BOLD_F, 26)196 words, lines, cur = lab.split(), [], ""197 for wd in words:198 probe = (cur + " " + wd).strip()199 if d.textlength(probe, font=lf) <= col - 26:200 cur = probe201 else:202 lines.append(cur); cur = wd203 lines.append(cur)204 for j, ln in enumerate(lines[:2]):205 d.text((x, ty + 78 + j * 34), ln, font=lf, fill=t["sub"])206 return img, d, t207208209def card_bars(site, dark, title, subtitle, rows, idx, note=None):210 """rows: (label, valeur_num, texte_valeur[, sous-texte])"""211 img, d, t = new_card(site, dark)212 header(d, img, site, t, title, subtitle, idx)213 top, bottom = 380, 1150 if note else 1210214 maxv = max(r[1] for r in rows)215 rowh = min((bottom - top) / len(rows), 132)216 for i, r in enumerate(rows):217 label, v, vtxt = r[0], r[1], r[2]218 sub = r[3] if len(r) > 3 else None219 y = top + int(i * rowh)220 d.text((64, y), label, font=f(BOLD_F, 33), fill=t["ink"])221 d.text((W - 64, y), vtxt, font=f(BLACK_F, 34), fill=t["hero"], anchor="ra")222 if sub:223 d.text((64, y + 44), sub, font=f(BOLD_F, 25), fill=t["sub"])224 by = y + (82 if sub else 48)225 d.rounded_rectangle([64, by, W - 64, by + 16], radius=8, fill=t["track"])226 fw = max(20, int((W - 128) * v / maxv))227 d.rounded_rectangle([64, by, 64 + fw, by + 16], radius=8, fill=t["bar"])228 if note:229 d.text((64, 1180), note, font=f(BOLD_F, 28), fill=t["sub"])230 return img, d, t231232233def card_tiles(site, dark, title, subtitle, tiles, idx, cols=2):234 img, d, t = new_card(site, dark)235 header(d, img, site, t, title, subtitle, idx)236 top = 400237 coln = cols238 colw = (W - 128) / coln239 rowh = 260240 for i, (val, lab) in enumerate(tiles):241 x = 64 + int((i % coln) * colw)242 y = top + (i // coln) * rowh243 vf = fit_font(d, val, BLACK_F, 74, colw - 40)244 d.text((x, y), val, font=vf, fill=t["hero"] if i % 2 == 0 else t["ink"])245 lf = f(BOLD_F, 28)246 words, lines, cur = lab.split(), [], ""247 for wd in words:248 probe = (cur + " " + wd).strip()249 if d.textlength(probe, font=lf) <= colw - 40:250 cur = probe251 else:252 lines.append(cur); cur = wd253 lines.append(cur)254 for j, ln in enumerate(lines[:2]):255 d.text((x, y + 96 + j * 36), ln, font=lf, fill=t["sub"])256 return img, d, t257258259def save(img, site, n):260 folder = os.path.join(OUT, site)261 os.makedirs(folder, exist_ok=True)262 p = os.path.join(folder, f"{n}.png")263 img.save(p)264 print(p)265266267# ============================== LOU-KA ==============================268site = "lou-ka"269img, d, t = card_hero(site, True, "Le marché locatif,", "mesuré en temps réel — pas estimé.",270 "45 684", "logements à louer actifs au Québec",271 [("189", "sources agrégées"), ("1 228", "villes couvertes"), ("97 %", "géolocalisés")], 1)272banner(d, site, t); save(img, site, 1)273274img, d, t = card_bars(site, False, "Où se situent", "les loyers ? (annonces avec prix)",275 [("Moins de 1 000 $", 4790, "4 790"),276 ("1 000 – 1 400 $", 11422, "11 422"),277 ("1 400 – 1 800 $", 17840, "17 840"),278 ("1 800 – 2 200 $", 12403, "12 403"),279 ("2 200 – 2 600 $", 6755, "6 755"),280 ("2 600 – 3 200 $", 3795, "3 795"),281 ("3 200 $ et plus", 2636, "2 636")], 2,282 note="Loyer moyen : 1 813 $ · médian : 1 700 $")283banner(d, site, t); save(img, site, 2)284285img, d, t = card_bars(site, True, "Le marché", "par taille de logement",286 [("4½", 21215, "21 215", "loyer moyen 1 946 $"),287 ("3½", 19247, "19 247", "loyer moyen 1 617 $"),288 ("5½", 7960, "7 960", "loyer moyen 2 218 $"),289 ("Studio", 3696, "3 696", "loyer moyen 1 406 $"),290 ("6½ et plus", 2629, "2 629", "loyer moyen 2 448 $"),291 ("Chambre", 1989, "1 989", "loyer moyen 766 $")], 3)292banner(d, site, t); save(img, site, 3)293294img, d, t = card_bars(site, False, "Top villes", "volume d'annonces et loyer moyen",295 [("Montréal", 24508, "24 508", "loyer moyen 1 901 $"),296 ("Québec", 4108, "4 108", "loyer moyen 1 513 $"),297 ("Laval", 3869, "3 869", "loyer moyen 2 062 $"),298 ("Gatineau", 3670, "3 670", "loyer moyen 1 728 $"),299 ("Lévis", 1679, "1 679", "loyer moyen 1 751 $"),300 ("Sherbrooke", 1381, "1 381", "loyer moyen 1 238 $")], 4)301banner(d, site, t); save(img, site, 4)302303img, d, t = card_tiles(site, True, "Un marché vivant,", "des données propres — 30 derniers jours",304 [("78 293", "nouvelles annonces détectées"),305 ("31 499", "annonces retirées (louées)"),306 ("10 449", "annonces sous le prix du marché"),307 ("91,4 %", "complétude moyenne des fiches"),308 ("1 111", "annonces en quarantaine qualité"),309 ("218", "connecteurs actifs")], 5)310banner(d, site, t); save(img, site, 5)311312# ============================== IMMO-KA ==============================313site = "immo-ka"314img, d, t = card_hero(site, True, "Toutes les propriétés", "à vendre, un seul site.",315 "66 061", "propriétés à vendre au Québec",316 [("45", "sources agrégées"), ("3 166", "villes"), ("673 090 $", "prix moyen affiché")], 1)317banner(d, site, t); save(img, site, 1)318319img, d, t = card_bars(site, False, "Prix affiché vs", "valeur réelle (croisement Vrai-Prix)",320 [("Sur-évaluées (+10 % et plus)", 48.2, "48,2 %"),321 ("Sous-évaluées (−5 % et moins)", 27.6, "27,6 %"),322 ("Prix justes (±5 %)", 24.3, "24,3 %")], 2,323 note="Écart médian affiché vs valeur : +8,7 % · 44 294 propriétés analysées")324banner(d, site, t); save(img, site, 2)325326img, d, t = card_bars(site, True, "Qui affiche le plus", "au-dessus de la valeur ? (écart médian)",327 [("Sotheby's Québec", 38.4, "+38,4 %", "549 inscriptions"),328 ("Image, l'agence", 25.7, "+25,7 %", "55 inscriptions"),329 ("Engel & Völkers", 22.1, "+22,1 %", "844 inscriptions"),330 ("eXp Québec", 17.9, "+17,9 %", "744 inscriptions"),331 ("LesPAC", 17.0, "+17,0 %", "1 052 inscriptions")], 3,332 note="Source : valeurs Vrai-Prix (modèle hédonique, erreur médiane 11 %)")333banner(d, site, t); save(img, site, 3)334335img, d, t = card_bars(site, False, "Volume par réseau", "inscriptions actives analysées",336 [("DuProprio", 5294, "5 294"),337 ("Via Capitale", 2826, "2 826"),338 ("Proprio Direct", 1788, "1 788"),339 ("LesPAC", 1052, "1 052"),340 ("Domicilia", 954, "954"),341 ("Ubee", 932, "932")], 4)342banner(d, site, t); save(img, site, 4)343344img, d, t = card_tiles(site, True, "Qualité des données", "chaque fiche passe l'inspection",345 [("79 674", "annonces actives suivies"),346 ("66 121", "fiches publiées"),347 ("82,8 %", "complétude moyenne"),348 ("13 553", "en quarantaine qualité"),349 ("4 013", "sans image — filtrées"),350 ("4 790", "superficies improbables bloquées")], 5)351banner(d, site, t); save(img, site, 5)352353# ============================== FOOD-KA ==============================354site = "food-ka"355img, d, t = card_hero(site, True, "L'épicerie comparée,", "chaque jour, bannière par bannière.",356 "50 180", "produits d'épicerie suivis",357 [("57", "sources"), ("8 633", "en solde maintenant"), ("16,86 $", "prix moyen")], 1)358banner(d, site, t); save(img, site, 1)359360img, d, t = card_bars(site, False, "Le panier", "par catégorie (prix moyen)",361 [("Garde-manger", 8833, "8 833", "prix moyen 8,70 $"),362 ("Boissons", 6023, "6 023", "prix moyen 8,38 $"),363 ("Collations", 4964, "4 964", "prix moyen 6,01 $"),364 ("Fruits et légumes", 3059, "3 059", "prix moyen 8,61 $"),365 ("Laitiers et œufs", 2653, "2 653", "prix moyen 14,32 $"),366 ("Viandes et volailles", 2262, "2 262", "prix moyen 14,79 $")], 2)367banner(d, site, t); save(img, site, 2)368369img, d, t = card_bars(site, True, "Les catalogues", "par bannière (produits suivis)",370 [("Giant Tiger", 9336, "9 336"),371 ("Épipresto", 6000, "6 000"),372 ("Boîte à Grains", 6000, "6 000"),373 ("Nuvo", 4797, "4 797"),374 ("PA", 3474, "3 474"),375 ("SAQ", 3289, "3 289")], 3)376banner(d, site, t); save(img, site, 3)377378img, d, t = card_bars(site, False, "Où sont les soldes ?", "part du catalogue en rabais",379 [("Metro", 32.6, "32,6 %"),380 ("Boîte à Grains", 21.1, "21,1 %"),381 ("Maxi", 12.2, "12,2 %"),382 ("Provigo", 10.4, "10,4 %"),383 ("Nuvo", 9.4, "9,4 %"),384 ("Giant Tiger", 6.5, "6,5 %")], 4)385banner(d, site, t); save(img, site, 4)386387img, d, t = card_tiles(site, True, "Comparer, vraiment", "le même produit, d'une bannière à l'autre",388 [("1 191", "groupes de produits équivalents"),389 ("2 825", "produits liés entre bannières"),390 ("554", "fiches nutritionnelles reliées"),391 ("18", "catégories classées"),392 ("8 633", "soldes repérés aujourd'hui"),393 ("24/7", "mise à jour continue")], 5)394banner(d, site, t); save(img, site, 5)395396# ============================== FABRI-KA ==============================397site = "fabri-ka"398img, d, t = card_hero(site, True, "Le savoir-faire", "québécois, agrégé en un catalogue.",399 "355 334", "produits québécois répertoriés",400 [("1 501", "boutiques en ligne"), ("17", "régions"), ("4 082", "au registre")], 1)401banner(d, site, t); save(img, site, 1)402403img, d, t = card_bars(site, False, "Les produits", "par région",404 [("Montréal", 56083, "56 083"),405 ("Outaouais", 32374, "32 374"),406 ("Saguenay–Lac-St-Jean", 23540, "23 540"),407 ("Laurentides", 18950, "18 950"),408 ("Montérégie", 15912, "15 912"),409 ("Estrie", 15716, "15 716")], 2)410banner(d, site, t); save(img, site, 2)411412img, d, t = card_bars(site, True, "Les boutiques", "par région",413 [("Montérégie", 484, "484"),414 ("Capitale-Nationale", 466, "466"),415 ("Estrie", 425, "425"),416 ("Montréal", 392, "392"),417 ("Saguenay–Lac-St-Jean", 318, "318"),418 ("Chaudière-Appalaches", 264, "264")], 3)419banner(d, site, t); save(img, site, 3)420421img, d, t = card_tiles(site, False, "Du registre", "au catalogue en ligne",422 [("4 082", "boutiques québécoises recensées"),423 ("1 501", "catalogues synchronisés en direct"),424 ("355 334", "produits en ligne, prix à jour"),425 ("17/17", "régions du Québec couvertes")], 4)426banner(d, site, t); save(img, site, 4)427428img, d, t = card_bars(site, True, "Le robot passe", "boutique par boutique (dernier passage)",429 [("melissanepton.com", 792, "792", "produits vérifiés"),430 ("kazakmtl.com", 345, "345", "produits vérifiés"),431 ("maguireshoes.com", 257, "257", "produits vérifiés"),432 ("mobican.com", 246, "246", "produits vérifiés"),433 ("maillagogo.com", 190, "190", "produits vérifiés")], 5,434 note="Synchronisation en continu, 24 h sur 24")435banner(d, site, t); save(img, site, 5)436