Path: blob/main/onlyfans_scraper/api/subscriptions.py
961 views
r"""1_ __2___ _ __ | | _ _ / _| __ _ _ __ ___ ___ ___ _ __ __ _ _ __ ___ _ __3/ _ \ | '_ \ | || | | || |_ / _` || '_ \ / __| _____ / __| / __|| '__| / _` || '_ \ / _ \| '__|4| (_) || | | || || |_| || _|| (_| || | | |\__ \|_____|\__ \| (__ | | | (_| || |_) || __/| |5\___/ |_| |_||_| \__, ||_| \__,_||_| |_||___/ |___/ \___||_| \__,_|| .__/ \___||_|6|___/ |_|7"""89import asyncio10from itertools import chain1112import httpx1314from ..constants import subscriptionsEP15from ..utils import auth, dates161718async def get_subscriptions(headers, subscribe_count):19offsets = range(0, subscribe_count, 10)20tasks = [scrape_subscriptions(headers, offset) for offset in offsets]21subscriptions = await asyncio.gather(*tasks)22return list(chain.from_iterable(subscriptions))232425async def scrape_subscriptions(headers, offset=0) -> list:26async with httpx.AsyncClient(http2=True, headers=headers) as c:27url = subscriptionsEP.format(offset)2829auth.add_cookies(c)30c.headers.update(auth.create_sign(url, headers))3132r = await c.get(subscriptionsEP.format(offset), timeout=None)33if not r.is_error:34subscriptions = r.json()35return subscriptions36r.raise_for_status()373839def parse_subscriptions(subscriptions: list) -> list:40data = [(profile['username'], profile['id'], dates.convert_date_to_mdyhms(41profile['subscribedByExpireDate'])) for profile in subscriptions]42return data434445def print_subscriptions(subscriptions: list):46fmt = '{:>4} {:^25} {:>15} {:^35}'47print(fmt.format('NUM', 'USERNAME', 'ID', 'EXPIRES ON'))48for c, t in enumerate(subscriptions, 1):49print(fmt.format(c, *t))505152