Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
taux1c
GitHub Repository: taux1c/onlyfans-scraper
Path: blob/main/onlyfans_scraper/api/subscriptions.py
961 views
1
r"""
2
_ __
3
___ _ __ | | _ _ / _| __ _ _ __ ___ ___ ___ _ __ __ _ _ __ ___ _ __
4
/ _ \ | '_ \ | || | | || |_ / _` || '_ \ / __| _____ / __| / __|| '__| / _` || '_ \ / _ \| '__|
5
| (_) || | | || || |_| || _|| (_| || | | |\__ \|_____|\__ \| (__ | | | (_| || |_) || __/| |
6
\___/ |_| |_||_| \__, ||_| \__,_||_| |_||___/ |___/ \___||_| \__,_|| .__/ \___||_|
7
|___/ |_|
8
"""
9
10
import asyncio
11
from itertools import chain
12
13
import httpx
14
15
from ..constants import subscriptionsEP
16
from ..utils import auth, dates
17
18
19
async def get_subscriptions(headers, subscribe_count):
20
offsets = range(0, subscribe_count, 10)
21
tasks = [scrape_subscriptions(headers, offset) for offset in offsets]
22
subscriptions = await asyncio.gather(*tasks)
23
return list(chain.from_iterable(subscriptions))
24
25
26
async def scrape_subscriptions(headers, offset=0) -> list:
27
async with httpx.AsyncClient(http2=True, headers=headers) as c:
28
url = subscriptionsEP.format(offset)
29
30
auth.add_cookies(c)
31
c.headers.update(auth.create_sign(url, headers))
32
33
r = await c.get(subscriptionsEP.format(offset), timeout=None)
34
if not r.is_error:
35
subscriptions = r.json()
36
return subscriptions
37
r.raise_for_status()
38
39
40
def parse_subscriptions(subscriptions: list) -> list:
41
data = [(profile['username'], profile['id'], dates.convert_date_to_mdyhms(
42
profile['subscribedByExpireDate'])) for profile in subscriptions]
43
return data
44
45
46
def print_subscriptions(subscriptions: list):
47
fmt = '{:>4} {:^25} {:>15} {:^35}'
48
print(fmt.format('NUM', 'USERNAME', 'ID', 'EXPIRES ON'))
49
for c, t in enumerate(subscriptions, 1):
50
print(fmt.format(c, *t))
51
52