-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtest.py
128 lines (102 loc) · 4.01 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import asyncio
from pathlib import Path
import ultima_scraper_api
from ultima_scraper_api import OnlyFansAPI, UltimaScraperAPIConfig
FULL_TEST = False
# def convert_to_snake_case():
# import inflection
# # import orjson
# from ultima_scraper_api.apis.fansly.classes.user_model import create_user
# # json = orjson.loads(Path("test.json").read_bytes())
# # me_json, performer_json = json[0], json[1]
# # missing_keys = set(me_json.keys()) - set(performer_json.keys())
# file_path = "ultima_scraper_api/apis/fansly/classes/user_model.py"
# abc = vars(create_user({"avatar": ""}, {}))
# with open(file_path, "r") as file:
# file_lines = file.readlines()
# for key in abc:
# underscore_key = inflection.underscore(key)
# old_string = f"self.{key}:"
# new_string = f"self.{underscore_key}:"
# for i, line in enumerate(file_lines):
# if old_string in line:
# line = file_lines[i]
# new_line = line.replace(old_string, new_string)
# file_lines[i] = new_line
# break
# with open(file_path, "w") as file:
# file.writelines(file_lines)
async def custom_auth(api: OnlyFansAPI):
import orjson
auth_path = Path("auth.json")
_auth_json = orjson.loads(auth_path.read_bytes())
authed = await api.login(_auth_json["auth"])
return authed
async def main():
async def authenticate(api: OnlyFansAPI):
"""
Authenticates the API using the provided OnlyFansAPI instance.
Parameters:
api (OnlyFansAPI): An instance of the OnlyFansAPI class.
Returns:
Tuple: A tuple containing the authenticated API instance and the guest authentication status.
"""
authed = None
guest_authed = await api.login(guest=True)
return authed, guest_authed
async def get_all_posts(authed: ultima_scraper_api.auth_types):
"""
Retrieves all posts from the authenticated user's account.
Parameters:
- authed (ultima_scraper_api.auth_types): An instance of the authentication class.
Returns:
- list: A list of all posts from the user's account.
"""
user = await authed.get_user("onlyfans")
if isinstance(user, ultima_scraper_api.user_types):
return await user.get_posts()
async def bulk_ip(authed: ultima_scraper_api.auth_types):
"""
Perform bulk IP requests using the provided authenticated session.
Args:
authed (ultima_scraper_api.auth_types): The authenticated session.
Returns:
None
"""
url = "https://checkip.amazonaws.com"
urls = [url] * 100
responses = await authed.auth_session.bulk_requests(urls)
for response in responses:
if response:
print(await response.read())
async def rate_limit_enabler(authed: ultima_scraper_api.auth_types):
"""
Enables rate limiting for the given authenticated session.
Args:
authed (ultima_scraper_api.auth_types): The authenticated session.
Returns:
None
"""
url = "https://onlyfans.com/api2/v2/init"
urls = [url] * 10000
responses = await authed.auth_session.bulk_json_requests(urls)
has_errors = any("error" in item for item in responses)
assert has_errors == False
config = UltimaScraperAPIConfig()
api = OnlyFansAPI(config)
authed, _guest_authed = await authenticate(api)
assert _guest_authed
authed = _guest_authed
if FULL_TEST:
await bulk_ip(authed)
await rate_limit_enabler(authed)
posts = await get_all_posts(authed)
if posts:
for post in posts:
if not post.text:
continue
author = post.get_author()
print(f"User: {author.username}\nContent: {post.text}")
break
await api.close_pools()
asyncio.run(main())