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_statcards.py11# Description : Cartes de stats « faites maison » pour les posts Facebook12# Groupe KA.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"""Cartes de stats « faites maison » pour les posts Facebook Groupe KA.9192Style maison (cohérent avec profile.png / cover.png) : charbon + lime + crème.931080×1350 (4:5). Nombre-héros + tuiles + mini-barres à étiquettes directes.94Stats live du 2026-08-22 (APIs /api/stats des sites).95"""96import os97from PIL import Image, ImageDraw, ImageFont9899CHARCOAL = (20, 24, 20)100CHARCOAL2 = (30, 36, 30) # piste des barres / panneaux101LIME = (217, 242, 107)102CREAM = (242, 241, 234)103GRAY = (150, 156, 148) # texte secondaire104RING = (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, 1350111OUT = os.path.join(os.path.dirname(os.path.abspath(__file__)), "statcards")112os.makedirs(OUT, exist_ok=True)113114115def f(path, size):116 return ImageFont.truetype(path, size)117118119def fr(n):120 return f"{n:,}".replace(",", " ")121122123def fit_font(d, text, path, size, max_w):124 while size > 40:125 fo = f(path, size)126 if d.textlength(text, font=fo) <= max_w:127 return fo128 size -= 6129 return f(path, size)130131132CARDS = [133 dict(slug="trouve-ka", name="Trouve·Ka", tag="Le moteur de recherche 100 % québécois.",134 hero="1 298 175", hero_label="pages web québécoises indexées",135 tiles=[("73 127", "domaines couverts"), ("16 334", "pages / heure"), ("100 %", "recherche sémantique")],136 bars_title="Le crawler tourne en continu, jour et nuit", bars=[],137 extra=[("2 676 235", "pages en attente de crawl"), ("24 / 7", "indexation en continu")],138 url="www.trouve-ka.com"),139 dict(slug="lou-ka", name="Lou·Ka", tag="Tous les logements à louer du Québec, au même endroit.",140 hero="45 649", hero_label="logements à louer agrégés",141 tiles=[("189", "sources"), ("1 808 $", "loyer moyen"), ("91,4 %", "complétude des fiches")],142 bars_title="Répartition des logements",143 bars=[("Montréal", 22981), ("Autres régions", 17790), ("Québec", 3491), ("Lévis", 1387)],144 url="www.lou-ka.com"),145 dict(slug="immo-ka", name="Immo·Ka", tag="Toutes les propriétés à vendre, un seul site.",146 hero="66 059", hero_label="propriétés à vendre au Québec",147 tiles=[("45", "sources"), ("3 166", "villes"), ("673 090 $", "prix moyen affiché")],148 bars_title="Prix affichés vs valeur Vrai-Prix",149 bars=[("Sur-évaluées (+10 %)", 48.2, "48,2 %"), ("Sous-évaluées (−5 %)", 27.6, "27,6 %"),150 ("Prix justes", 24.3, "24,3 %")],151 url="www.immo-ka.com"),152 dict(slug="vrai-prix", name="Vrai-Prix", tag="La vraie valeur de chaque propriété du Québec.",153 hero="3 747 008", hero_label="unités d'évaluation couvertes",154 tiles=[("2 009 G$", "valeur totale 2026"), ("444 300 $", "valeur médiane"), ("+43,1 %", "croissance 2021→2026")],155 bars_title="Modèle hédonique + comparables — erreur médiane 11 %",156 bars=[], extra=[("1 097", "municipalités"), ("745 119", "transactions analysées")],157 url="www.vrai-prix.com"),158 dict(slug="auto-ka", name="Auto·Ka", tag="Le marché de l'occasion, décodé.",159 hero="37 803", hero_label="véhicules d'occasion en vente",160 tiles=[("128", "sources"), ("31 728 $", "prix moyen"), ("16 969", "rappels croisés")],161 bars_title="Top régions",162 bars=[("Montérégie", 7007), ("Capitale-Nationale", 4274), ("Laurentides", 3806),163 ("Montréal", 3248), ("Chaudière-Appalaches", 2578)],164 url="www.auto-ka.com"),165 dict(slug="fabri-ka", name="Fabri·Ka", tag="Le savoir-faire québécois, agrégé.",166 hero="355 334", hero_label="produits québécois répertoriés",167 tiles=[("1 501", "boutiques en ligne"), ("17", "régions couvertes"), ("4 082", "boutiques au registre")],168 bars_title="Top régions (produits)",169 bars=[("Montréal", 56083), ("Outaouais", 32374), ("Saguenay–Lac-St-Jean", 23540),170 ("Laurentides", 18950), ("Montérégie", 15912)],171 url="www.fabri-ka.com"),172 dict(slug="food-ka", name="Food·Ka", tag="L'épicerie comparée, chaque jour.",173 hero="50 180", hero_label="produits d'épicerie suivis",174 tiles=[("57", "sources"), ("8 633", "en solde maintenant"), ("16,86 $", "prix moyen")],175 bars_title="Top sources (produits)",176 bars=[("Giant Tiger", 9336), ("Épipresto", 6000), ("Boîte à Grains", 6000),177 ("Nuvo", 4797), ("PA", 3474)],178 url="www.food-ka.com"),179 dict(slug="resto-ka", name="Resto·Ka", tag="Tous les restos du Québec, une seule adresse.",180 hero="14 666", hero_label="restaurants répertoriés",181 tiles=[("120 338", "plats aux menus"), ("1 309", "menus complets"), ("17", "régions")],182 bars_title="Top régions",183 bars=[("Montréal", 5480), ("Montérégie", 2112), ("Capitale-Nationale", 1192),184 ("Laval", 1029), ("Laurentides", 795)],185 url="www.resto-ka.com"),186 dict(slug="sorti-ka", name="Sorti·Ka", tag="Toutes les sorties du Québec, en un coup d'œil.",187 hero="17 875", hero_label="événements à venir",188 tiles=[("3 669", "gratuits"), ("347", "villes"), ("29", "sources")],189 bars_title="Top régions",190 bars=[("Montréal", 6495), ("Capitale-Nationale", 3171), ("Estrie", 964),191 ("Montérégie", 936), ("Saguenay–Lac-St-Jean", 774)],192 url="www.sorti-ka.com"),193 dict(slug="crea-ka", name="Créa·Ka", tag="Les créateurs de contenu d'ici, cartographiés.",194 hero="12 861", hero_label="créateurs québécois recensés",195 tiles=[("18 839", "comptes reliés"), ("19", "plateformes"), ("20", "niches")],196 bars_title="Top plateformes",197 bars=[("YouTube", 9977), ("Instagram", 3353), ("Facebook", 1517),198 ("TikTok", 985), ("X", 850)],199 url="www.crea-ka.com"),200]201202203def draw_card(c):204 img = Image.new("RGB", (W, H), CHARCOAL)205 d = ImageDraw.Draw(img)206 d.rounded_rectangle([16, 16, W - 16, H - 16], radius=26, outline=RING, width=3)207208 # Eyebrow209 d.line([64, 92, 112, 92], fill=LIME, width=6)210 d.text((130, 92), "S T A T S L I V E · 2 2 A O Û T 2 0 2 6",211 font=f(BOLD_F, 27), fill=LIME, anchor="lm")212213 # Boîte KA inclinée en haut à droite214 box = Image.new("RGBA", (150, 96, ) , (0, 0, 0, 0))215 bd = ImageDraw.Draw(box)216 bd.rounded_rectangle([0, 0, 149, 95], radius=20, fill=LIME)217 bd.text((75, 48), "KA", font=f(BLACK_F, 58), fill=CHARCOAL, anchor="mm")218 box = box.rotate(-4, expand=True, resample=Image.BICUBIC)219 img.paste(box, (W - 64 - box.width, 52), box)220221 # Nom du site + tagline222 d.text((64, 165), c["name"], font=f(BLACK_F, 92), fill=CREAM)223 d.text((66, 300), c["tag"], font=f(BOLD_F, 33), fill=GRAY)224225 # Nombre-héros226 hero_font = fit_font(d, c["hero"], BLACK_F, 176, W - 128)227 d.text((60, 380), c["hero"], font=hero_font, fill=LIME)228 hero_h = hero_font.size229 d.text((66, 380 + hero_h + 48), c["hero_label"], font=f(BOLD_F, 41), fill=CREAM)230231 # Tuiles232 ty = 690233 d.line([64, ty - 26, W - 64, ty - 26], fill=RING, width=2)234 col_w = (W - 128) / 3235 for i, (val, lab) in enumerate(c["tiles"]):236 x = 64 + int(i * col_w)237 vf = fit_font(d, val, BLACK_F, 54, col_w - 28)238 d.text((x, ty), val, font=vf, fill=CREAM)239 # label sur 2 lignes max240 words, lines, cur = lab.split(), [], ""241 lf = f(BOLD_F, 26)242 for wd in words:243 t = (cur + " " + wd).strip()244 if d.textlength(t, font=lf) <= col_w - 28:245 cur = t246 else:247 lines.append(cur); cur = wd248 lines.append(cur)249 for j, ln in enumerate(lines[:2]):250 d.text((x, ty + 74 + j * 34), ln, font=lf, fill=GRAY)251252 # Section barres (étiquettes directes, piste = pas foncé du même fond)253 by = 880254 d.text((64, by), c["bars_title"].upper(), font=f(BOLD_F, 26), fill=GRAY)255 bars = c.get("bars", [])256 if bars:257 maxv = max(b[1] for b in bars)258 bar_x, bar_w = 64, W - 128259 rowh = (1230 - (by + 56)) / len(bars)260 rowh = min(rowh, 74)261 for i, b in enumerate(bars):262 label, v = b[0], b[1]263 vtxt = b[2] if len(b) > 2 else fr(v)264 y = by + 56 + int(i * rowh)265 lf2 = f(BOLD_F, 29)266 d.text((bar_x, y), label, font=lf2, fill=CREAM)267 d.text((bar_x + bar_w, y), vtxt, font=lf2, fill=LIME, anchor="ra")268 ty2 = y + 40269 d.rounded_rectangle([bar_x, ty2, bar_x + bar_w, ty2 + 14], radius=7, fill=CHARCOAL2)270 fw = max(18, int(bar_w * v / maxv))271 d.rounded_rectangle([bar_x, ty2, bar_x + fw, ty2 + 14], radius=7, fill=LIME)272 else:273 # tuiles supplémentaires à la place des barres274 extra = c.get("extra", [])275 for i, (val, lab) in enumerate(extra):276 x = 64 + int(i * (W - 128) / 2)277 d.text((x, by + 60), val, font=f(BLACK_F, 62), fill=CREAM)278 d.text((x, by + 148), lab, font=f(BOLD_F, 28), fill=GRAY)279280 # Bandeau bas281 d.rounded_rectangle([16, 1246, W - 16, H - 16], radius=26, fill=LIME)282 d.text((64, 1290), c["url"], font=f(MONO_F, 40), fill=CHARCOAL, anchor="lm")283 d.text((W - 64, 1290), "GROUPE ·KA", font=f(BLACK_F, 34), fill=CHARCOAL, anchor="rm")284285 path = os.path.join(OUT, c["slug"] + ".png")286 img.save(path)287 print(path)288289290for c in CARDS:291 draw_card(c)292