Repository Public
1# =============================================================================2# SP BOUCHER | SOFTWARE & RESEARCH3# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project : KA Apify Actors9# File : ka-patreon/src/main.py10# Module : ka-patreon11# Repository : https://git.spboucher.ai/ka-apify-actors12# Created : 2026-08-1813# Last Modified : 2026-08-1814#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# Author: Simon-Pierre Boucher <contact@spboucher.ai>89# File: src/main.py (ka-patreon)90# Desc: Pages Patreon publiques — la page /<vanity> embarque l'objet campagne91# (patron_count, creation_count, is_monthly, pay_per_name, résumé) +92# og:title/og:image. Aucune clé. Proxy résidentiel recommandé.93# ==============================================================================94from __future__ import annotations9596import asyncio97import html as htmllib98import json99import re100101from apify import Actor102103from .net import Fetcher104105PAGE_URL = "https://www.patreon.com/{u}"106_NUM = {107 "patrons": re.compile(r'"patron_count"\s*:\s*(\d+)'),108 "posts": re.compile(r'"creation_count"\s*:\s*(\d+)'),109 "paid_posts": re.compile(r'"paid_member_count"\s*:\s*(\d+)'),110}111_OG_TITLE = re.compile(r'<meta property="og:title" content="([^"]*)"')112_OG_IMG = re.compile(r'<meta property="og:image" content="([^"]*)"')113_OG_DESC = re.compile(r'<meta property="og:description" content="([^"]*)"')114_MONTHLY = re.compile(r'"is_monthly"\s*:\s*(true|false)')115_NSFW = re.compile(r'"is_nsfw"\s*:\s*(true|false)')116117118async def main() -> None:119 async with Actor:120 inp = await Actor.get_input() or {}121 usernames = [u.strip().lstrip("@").lower()122 for u in (inp.get("usernames") or []) if u and u.strip()]123 proxy = await Actor.create_proxy_configuration(124 actor_proxy_input=inp.get("proxyConfiguration"))125 fetcher = Fetcher(proxy, delay=float(inp.get("requestDelay") or 1))126 sem = asyncio.Semaphore(int(inp.get("concurrency") or 4))127128 async def one(u: str) -> None:129 async with sem:130 miss = {"kind": "profile", "platform": "patreon",131 "username": u, "found": False}132 try:133 resp = await fetcher.get(PAGE_URL.format(u=u),134 session_id=u)135 except Exception as exc:136 await Actor.push_data({**miss, "error": str(exc)[:200]})137 return138 text = resp.text or ""139 if resp.status_code == 404:140 await Actor.push_data({**miss, "error": "http_404"})141 return142 m = _NUM["patrons"].search(text)143 if resp.status_code != 200 or not m:144 await Actor.push_data(145 {**miss, "error": f"http_{resp.status_code}"})146 return147148 def num(key):149 mm = _NUM[key].search(text)150 return int(mm.group(1)) if mm else None151 title = _OG_TITLE.search(text)152 img = _OG_IMG.search(text)153 desc = _OG_DESC.search(text)154 monthly = _MONTHLY.search(text)155 nsfw = _NSFW.search(text)156 name = htmllib.unescape(title.group(1)) if title else u157 name = re.sub(r"\s*\|\s*Patreon\s*$", "", name).strip()158 await Actor.push_data({159 "kind": "profile",160 "platform": "patreon",161 "found": True,162 "username": u,163 "full_name": name,164 "biography": (htmllib.unescape(desc.group(1))165 if desc else None),166 "followers": num("patrons"), # patrons = « abonnés » KA167 "patrons": num("patrons"),168 "posts_count": num("posts"),169 "is_monthly": (monthly.group(1) == "true"170 if monthly else None),171 "is_nsfw": nsfw.group(1) == "true" if nsfw else None,172 "avatar": htmllib.unescape(img.group(1)) if img else None,173 })174175 await asyncio.gather(*[one(u) for u in usernames])176 Actor.log.info(f"terminé : {len(usernames)} pages")177