Path: blob/main/onlyfans_scraper/utils/prompts.py
961 views
r"""1_ __2___ _ __ | | _ _ / _| __ _ _ __ ___ ___ ___ _ __ __ _ _ __ ___ _ __3/ _ \ | '_ \ | || | | || |_ / _` || '_ \ / __| _____ / __| / __|| '__| / _` || '_ \ / _ \| '__|4| (_) || | | || || |_| || _|| (_| || | | |\__ \|_____|\__ \| (__ | | | (_| || |_) || __/| |5\___/ |_| |_||_| \__, ||_| \__,_||_| |_||___/ |___/ \___||_| \__,_|| .__/ \___||_|6|___/ |_|7"""89import re101112from InquirerPy.resolver import prompt13from InquirerPy.separator import Separator14from InquirerPy.base import Choice1516from ..constants import mainPromptChoices, usernameOrListChoices, profilesPromptChoices171819def main_prompt() -> int:20main_prompt_choices = [*mainPromptChoices]21main_prompt_choices.insert(3, Separator())2223name = 'action'2425questions = [26{27'type': 'list',28'name': name,29'message': 'What would you like to do?',30'choices': [*main_prompt_choices]31}32]3334answer = prompt(questions)35return mainPromptChoices[answer[name]]363738def username_or_list_prompt() -> int:39name = 'username_or_list'4041questions = [42{43'type': 'list',44'name': name,45'message': 'Choose one of the following options:',46'choices': [*usernameOrListChoices]47}48]4950answer = prompt(questions)51return usernameOrListChoices[answer[name]]525354def verify_all_users_username_or_list_prompt() -> bool:55name = 'all_users'5657questions = [58{59'type': 'confirm',60'name': name,61'message': 'Are you sure you want to scrape every model that you\'re subscribed to?',62'default': False63}64]6566answer = prompt(questions)67return answer[name]686970def username_prompt() -> str:71name = 'username'7273questions = [74{75'type': 'input',76'name': name,77'message': 'Enter a model\'s username:'78}79]8081answer = prompt(questions)82return answer[name]838485def areas_prompt() -> list:86name = 'areas'8788questions = [89{90'type': 'checkbox',91'qmark': '[?]',92'name': name,93'message': 'Which area(s) would you like to scrape? (Press ENTER to continue)',94'choices': [95Choice('All', enabled=True),96Choice('Timeline'),97Choice('Archived'),98Choice('Highlights'),99Choice('Messages'),100]101}102]103104while True:105answers = prompt(questions)106if not answers[name]:107print('Error: You must select at least one.')108break109return answers[name]110111112def database_prompt() -> tuple:113name1 = 'path'114name2 = 'username'115116questions = [117{118'type': 'input',119'name': name1,120'message': 'Enter the path to the directory that contains your database files:'121},122{123'type': 'input',124'name': name2,125'message': 'Enter that model\'s username:'126}127]128129answers = prompt(questions)130return (answers[name1], answers[name2])131132133def auth_prompt(auth) -> dict:134questions = [135{136'type': 'input',137'name': 'app-token',138'message': 'Enter your `app-token` value:',139'default': auth['app-token']140},141{142'type': 'input',143'name': 'sess',144'message': 'Enter your `sess` cookie:',145'default': auth['sess']146},147{148'type': 'input',149'name': 'auth_id',150'message': 'Enter your `auth_id` cookie:',151'default': auth['auth_id']152},153{154'type': 'input',155'name': 'auth_uid_',156'message': 'Enter your `auth_uid_` cookie (leave blank if you don\'t use 2FA):',157'default': auth['auth_uid_']158},159{160'type': 'input',161'name': 'user_agent',162'message': 'Enter your `user agent`:',163'default': auth['user_agent']164},165{166'type': 'input',167'name': 'x-bc',168'message': 'Enter your `x-bc` token:',169'default': auth['x-bc']170}171]172173answers = prompt(questions)174return answers175176177def ask_make_auth_prompt() -> bool:178name = 'make_auth'179180questions = [181{182'type': 'confirm',183'name': name,184'message': "It doesn't seem you have an `auth.json` file. Would you like to make one?",185}186]187188answer = prompt(questions)189return answer[name]190191192def profiles_prompt() -> int:193name = 'profile'194195questions = [196{197'type': 'list',198'name': name,199'message': 'Select one of the following:',200'choices': [*profilesPromptChoices]201}202]203204answer = prompt(questions)205return profilesPromptChoices[answer[name]]206207208def edit_profiles_prompt(profiles) -> str:209name = 'edit'210211profile_names = [profile.stem for profile in profiles]212213questions = [214{215'type': 'list',216'name': name,217'message': 'Which profile would you like to edit?',218'choices': [*profile_names]219}220]221222answer = prompt(questions)223return answer[name]224225226def new_name_edit_profiles_prompt(old_profile_name) -> str:227name = 'new_name'228229questions = [230{231'type': 'input',232'name': name,233'message': f'What would you like to rename {old_profile_name} to?'234}235]236237answer = prompt(questions)238return answer[name]239240241def create_profiles_prompt() -> str:242name = 'create'243244questions = [245{246'type': 'input',247'name': name,248'message': 'What would you like to name your new profile? [ONLY letters, numbers, and underscores!]'249}250]251252while True:253pattern = re.compile(r'[^\w+^\d+^_+]')254answer = prompt(questions)255256if not answer[name]:257print('You must type a name. Try again.')258259if re.search(pattern, answer[name]):260print('Profile name contains invalid characters. Try again.')261break262263return answer[name]264265266def get_profile_prompt(profiles: list) -> str:267name = 'get_profile'268269questions = [270{271'type': 'input',272'name': name,273'message': 'Enter a profile:'274}275]276277while True:278answer = prompt(questions)279profile = answer[name]280281if profile not in profiles:282print(profile)283print(profiles)284print('That profile does not exist.')285else:286break287288return profile289290291def config_prompt(config) -> dict:292questions = [293{294'type': 'input',295'name': 'main_profile',296'message': 'What would you like your main profile to be?',297'default': config['main_profile']298},299{300'type': 'input',301'name': 'save_location',302'message': 'Where would you like to save downloaded content?',303'default': config.get('save_location', '')304},305{306'type': 'input',307'name': 'file_size_limit',308'message': 'File size limit (enter a value in bytes):',309'default': config.get('file_size_limit', '')310}311]312313answers = prompt(questions)314answers.update({'save_location': answers.get(315'save_location').strip('\"')})316return answers317318319