SPB Git

Repository Public

main.py 7.4 KB 180 lines python

1# =============================================================================2#                  SP BOUCHER | SOFTWARE & RESEARCH3#             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# PROJECT METADATA7# -----------------------------------------------------------------------------8# Project          : KA Apify Actors9# File             : ka-fansly/src/main.py10# Module           : ka-fansly11# 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-fansly)90# Desc:   Profils Fansly via l'API publique apiv3.fansly.com/api/v1/account91#         (?usernames=) : abonnés (followCount), bio, badge, compteurs de92#         médias (images/vidéos), avatar/bannière. Lots de 20 handles/requête.93# ==============================================================================94from __future__ import annotations9596import asyncio97import json9899from apify import Actor100101from .net import Fetcher102103API_URL = ("https://apiv3.fansly.com/api/v1/account"104           "?usernames={us}&ngsw-bypass=true")105106107def _loc(media: dict | None) -> str | None:108    """Objet média Fansly → URL de la première variante disponible."""109    if not isinstance(media, dict):110        return None111    for variant in ([media] + (media.get("variants") or [])):112        for loc in (variant.get("locations") or []):113            if loc.get("location"):114                return loc["location"]115    return None116117118async 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))126127        found: set[str] = set()128        for i in range(0, len(usernames), 20):129            batch = usernames[i:i + 20]130            try:131                resp = await fetcher.get(API_URL.format(us=",".join(batch)),132                                         session_id=f"b{i}",133                                         headers={"Accept":134                                                  "application/json"})135                data = (json.loads(resp.text)136                        if resp.status_code == 200 else {})137            except Exception as exc:138                for u in batch:139                    await Actor.push_data(140                        {"kind": "profile", "platform": "fansly",141                         "username": u, "found": False,142                         "error": str(exc)[:200]})143                continue144            for acc in (data.get("response") or []):145                u = str(acc.get("username") or "").lower()146                if not u:147                    continue148                found.add(u)149                stats = acc.get("timelineStats") or {}150                await Actor.push_data({151                    "kind": "profile",152                    "platform": "fansly",153                    "found": True,154                    "id": acc.get("id"),155                    "username": u,156                    "full_name": acc.get("displayName") or u,157                    "biography": (acc.get("about") or "")[:1000],158                    "followers": acc.get("followCount"),159                    "following": acc.get("followingCount"),160                    "is_verified": bool((acc.get("statusInfo") or {})161                                        .get("verified")162                                        or acc.get("verified")),163                    "posts_count": acc.get("postCount")164                                   or stats.get("postCount"),165                    "images_count": stats.get("imageCount"),166                    "videos_count": stats.get("videoCount"),167                    "likes": acc.get("accountMediaLikes"),168                    "avatar": _loc(acc.get("avatar")),169                    "banner": _loc(acc.get("banner")),170                    "location": acc.get("location"),171                })172            for u in batch:173                if u not in found:174                    await Actor.push_data(175                        {"kind": "profile", "platform": "fansly",176                         "username": u, "found": False,177                         "error": f"not_found_{resp.status_code}"})178        Actor.log.info(f"terminé : {len(usernames)} profils, "179                       f"{len(found)} trouvés")180
Files main
Menu

Theme