Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
taux1c
GitHub Repository: taux1c/onlyfans-scraper
Path: blob/main/onlyfans_scraper/utils/prompts.py
961 views
1
r"""
2
_ __
3
___ _ __ | | _ _ / _| __ _ _ __ ___ ___ ___ _ __ __ _ _ __ ___ _ __
4
/ _ \ | '_ \ | || | | || |_ / _` || '_ \ / __| _____ / __| / __|| '__| / _` || '_ \ / _ \| '__|
5
| (_) || | | || || |_| || _|| (_| || | | |\__ \|_____|\__ \| (__ | | | (_| || |_) || __/| |
6
\___/ |_| |_||_| \__, ||_| \__,_||_| |_||___/ |___/ \___||_| \__,_|| .__/ \___||_|
7
|___/ |_|
8
"""
9
10
import re
11
12
13
from InquirerPy.resolver import prompt
14
from InquirerPy.separator import Separator
15
from InquirerPy.base import Choice
16
17
from ..constants import mainPromptChoices, usernameOrListChoices, profilesPromptChoices
18
19
20
def main_prompt() -> int:
21
main_prompt_choices = [*mainPromptChoices]
22
main_prompt_choices.insert(3, Separator())
23
24
name = 'action'
25
26
questions = [
27
{
28
'type': 'list',
29
'name': name,
30
'message': 'What would you like to do?',
31
'choices': [*main_prompt_choices]
32
}
33
]
34
35
answer = prompt(questions)
36
return mainPromptChoices[answer[name]]
37
38
39
def username_or_list_prompt() -> int:
40
name = 'username_or_list'
41
42
questions = [
43
{
44
'type': 'list',
45
'name': name,
46
'message': 'Choose one of the following options:',
47
'choices': [*usernameOrListChoices]
48
}
49
]
50
51
answer = prompt(questions)
52
return usernameOrListChoices[answer[name]]
53
54
55
def verify_all_users_username_or_list_prompt() -> bool:
56
name = 'all_users'
57
58
questions = [
59
{
60
'type': 'confirm',
61
'name': name,
62
'message': 'Are you sure you want to scrape every model that you\'re subscribed to?',
63
'default': False
64
}
65
]
66
67
answer = prompt(questions)
68
return answer[name]
69
70
71
def username_prompt() -> str:
72
name = 'username'
73
74
questions = [
75
{
76
'type': 'input',
77
'name': name,
78
'message': 'Enter a model\'s username:'
79
}
80
]
81
82
answer = prompt(questions)
83
return answer[name]
84
85
86
def areas_prompt() -> list:
87
name = 'areas'
88
89
questions = [
90
{
91
'type': 'checkbox',
92
'qmark': '[?]',
93
'name': name,
94
'message': 'Which area(s) would you like to scrape? (Press ENTER to continue)',
95
'choices': [
96
Choice('All', enabled=True),
97
Choice('Timeline'),
98
Choice('Archived'),
99
Choice('Highlights'),
100
Choice('Messages'),
101
]
102
}
103
]
104
105
while True:
106
answers = prompt(questions)
107
if not answers[name]:
108
print('Error: You must select at least one.')
109
break
110
return answers[name]
111
112
113
def database_prompt() -> tuple:
114
name1 = 'path'
115
name2 = 'username'
116
117
questions = [
118
{
119
'type': 'input',
120
'name': name1,
121
'message': 'Enter the path to the directory that contains your database files:'
122
},
123
{
124
'type': 'input',
125
'name': name2,
126
'message': 'Enter that model\'s username:'
127
}
128
]
129
130
answers = prompt(questions)
131
return (answers[name1], answers[name2])
132
133
134
def auth_prompt(auth) -> dict:
135
questions = [
136
{
137
'type': 'input',
138
'name': 'app-token',
139
'message': 'Enter your `app-token` value:',
140
'default': auth['app-token']
141
},
142
{
143
'type': 'input',
144
'name': 'sess',
145
'message': 'Enter your `sess` cookie:',
146
'default': auth['sess']
147
},
148
{
149
'type': 'input',
150
'name': 'auth_id',
151
'message': 'Enter your `auth_id` cookie:',
152
'default': auth['auth_id']
153
},
154
{
155
'type': 'input',
156
'name': 'auth_uid_',
157
'message': 'Enter your `auth_uid_` cookie (leave blank if you don\'t use 2FA):',
158
'default': auth['auth_uid_']
159
},
160
{
161
'type': 'input',
162
'name': 'user_agent',
163
'message': 'Enter your `user agent`:',
164
'default': auth['user_agent']
165
},
166
{
167
'type': 'input',
168
'name': 'x-bc',
169
'message': 'Enter your `x-bc` token:',
170
'default': auth['x-bc']
171
}
172
]
173
174
answers = prompt(questions)
175
return answers
176
177
178
def ask_make_auth_prompt() -> bool:
179
name = 'make_auth'
180
181
questions = [
182
{
183
'type': 'confirm',
184
'name': name,
185
'message': "It doesn't seem you have an `auth.json` file. Would you like to make one?",
186
}
187
]
188
189
answer = prompt(questions)
190
return answer[name]
191
192
193
def profiles_prompt() -> int:
194
name = 'profile'
195
196
questions = [
197
{
198
'type': 'list',
199
'name': name,
200
'message': 'Select one of the following:',
201
'choices': [*profilesPromptChoices]
202
}
203
]
204
205
answer = prompt(questions)
206
return profilesPromptChoices[answer[name]]
207
208
209
def edit_profiles_prompt(profiles) -> str:
210
name = 'edit'
211
212
profile_names = [profile.stem for profile in profiles]
213
214
questions = [
215
{
216
'type': 'list',
217
'name': name,
218
'message': 'Which profile would you like to edit?',
219
'choices': [*profile_names]
220
}
221
]
222
223
answer = prompt(questions)
224
return answer[name]
225
226
227
def new_name_edit_profiles_prompt(old_profile_name) -> str:
228
name = 'new_name'
229
230
questions = [
231
{
232
'type': 'input',
233
'name': name,
234
'message': f'What would you like to rename {old_profile_name} to?'
235
}
236
]
237
238
answer = prompt(questions)
239
return answer[name]
240
241
242
def create_profiles_prompt() -> str:
243
name = 'create'
244
245
questions = [
246
{
247
'type': 'input',
248
'name': name,
249
'message': 'What would you like to name your new profile? [ONLY letters, numbers, and underscores!]'
250
}
251
]
252
253
while True:
254
pattern = re.compile(r'[^\w+^\d+^_+]')
255
answer = prompt(questions)
256
257
if not answer[name]:
258
print('You must type a name. Try again.')
259
260
if re.search(pattern, answer[name]):
261
print('Profile name contains invalid characters. Try again.')
262
break
263
264
return answer[name]
265
266
267
def get_profile_prompt(profiles: list) -> str:
268
name = 'get_profile'
269
270
questions = [
271
{
272
'type': 'input',
273
'name': name,
274
'message': 'Enter a profile:'
275
}
276
]
277
278
while True:
279
answer = prompt(questions)
280
profile = answer[name]
281
282
if profile not in profiles:
283
print(profile)
284
print(profiles)
285
print('That profile does not exist.')
286
else:
287
break
288
289
return profile
290
291
292
def config_prompt(config) -> dict:
293
questions = [
294
{
295
'type': 'input',
296
'name': 'main_profile',
297
'message': 'What would you like your main profile to be?',
298
'default': config['main_profile']
299
},
300
{
301
'type': 'input',
302
'name': 'save_location',
303
'message': 'Where would you like to save downloaded content?',
304
'default': config.get('save_location', '')
305
},
306
{
307
'type': 'input',
308
'name': 'file_size_limit',
309
'message': 'File size limit (enter a value in bytes):',
310
'default': config.get('file_size_limit', '')
311
}
312
]
313
314
answers = prompt(questions)
315
answers.update({'save_location': answers.get(
316
'save_location').strip('\"')})
317
return answers
318
319