Repository Public
1#!/usr/bin/env python32# =============================================================================3# SP BOUCHER | SOFTWARE & RESEARCH4# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5# =============================================================================6#7# PROJECT METADATA8# -----------------------------------------------------------------------------9# Project : Fabri·Ka10# File : scripts/reprobe_generic.py11# Description : Détecte les boutiques récoltables par le connecteur12# générique.13# Module : scripts14# Repository : https://git.spboucher.ai/fabri-ka15# Created : 2026-08-1216# Last Modified : 2026-08-1217#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"""Détecte les boutiques récoltables par le connecteur générique.9192Pour chaque boutique active SANS endpoint catalogue : teste si son sitemap93expose des pages produit dont le balisage (JSON-LD/microdata/og) est94extractible. Si oui → marque catalog_endpoint='__generic__' dans le cache95de vérification (repris par build_registry). Scrapfly en secours.96"""97import concurrent.futures as cf98import json99import os100import sys101102import requests103104ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))105sys.path.insert(0, ROOT)106CACHE = os.path.join(ROOT, "data", "verify_cache")107108for line in open(os.path.join(ROOT, ".env")).read().splitlines():109 if "=" in line and not line.startswith("#"):110 k, _, v = line.partition("=")111 os.environ.setdefault(k.strip(), v.strip())112113from fabrika.connectors.generic import GenericConnector, extract_product # noqa: E402114115UA = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 Chrome/126 Safari/537.36"116117118def test_domain(dom):119 sess = requests.Session()120 sess.headers["User-Agent"] = UA121 conn = GenericConnector({"id": dom, "url": f"https://{dom}"})122 conn.session = sess123 conn.use_scrapfly = False # détection rapide, sans anti-bot124 conn.timeout = 12125 try:126 urls = conn._sitemap_products()127 except Exception:128 return dom, None, 0129 if len(urls) < 3:130 return dom, None, len(urls)131 hits = 0132 for u in urls[:6]:133 try:134 html = conn._fetch_html(u)135 if html and extract_product(u, html):136 hits += 1137 except Exception:138 pass139 if hits >= 3:140 break141 ok = hits >= 3142 return dom, ok, len(urls)143144145def main():146 reg = json.load(open(os.path.join(ROOT, "data", "stores.json")))["stores"]147 # candidats : actives, pas déjà connectables, plateforme compatible rendu serveur148 server_plats = {"", "prestashop", "magento", "bigcommerce", "lightspeed",149 "snipcart", "wordpress", "woocommerce", "squarespace"}150 targets = [s["id"] for s in reg151 if not s.get("catalog_endpoint") and (s.get("platform") or "") in server_plats]152 print(f"test générique sur {len(targets)} boutiques")153 found = 0154 done = 0155 with cf.ThreadPoolExecutor(10) as ex:156 for dom, ok, n in ex.map(test_domain, targets):157 done += 1158 if ok:159 found += 1160 cpath = os.path.join(CACHE, dom + ".json")161 try:162 rec = json.load(open(cpath))163 except Exception:164 rec = {"domain": dom, "active": True, "final_domain": dom}165 if not rec.get("platform"):166 rec["platform"] = "generic"167 rec["catalog_endpoint"] = "__generic__"168 json.dump(rec, open(cpath, "w"))169 print(f" ✓ {dom} ({n} pages produit)", flush=True)170 if done % 200 == 0:171 print(f" … {done}/{len(targets)} — {found} récoltables", flush=True)172 print(f"nouvelles boutiques génériques: {found}/{len(targets)}")173174175if __name__ == "__main__":176 main()177