Path: blob/main/onlyfans_scraper/utils/profiles.py
961 views
r"""1_ __2___ _ __ | | _ _ / _| __ _ _ __ ___ ___ ___ _ __ __ _ _ __ ___ _ __3/ _ \ | '_ \ | || | | || |_ / _` || '_ \ / __| _____ / __| / __|| '__| / _` || '_ \ / _ \| '__|4| (_) || | | || || |_| || _|| (_| || | | |\__ \|_____|\__ \| (__ | | | (_| || |_) || __/| |5\___/ |_| |_||_| \__, ||_| \__,_||_| |_||___/ |___/ \___||_| \__,_|| .__/ \___||_|6|___/ |_|7"""89import pathlib10import shutil1112from .config import read_config, update_config13from .prompts import get_profile_prompt14from ..constants import configPath, configFile, mainProfile15configPath = '.config/onlyfans-scraper'161718def get_profile_path():19config_path = pathlib.Path.home() / configPath20return config_path212223def get_profiles() -> list:24config_path = get_profile_path()2526# (This block of code should be removed in the 1.0 release)27#28# If user upgraded from an older version of onlyfans-scraper or if the user29# has an auth.json or models.db file in the config_path:30# if has_files(config_path):31# create_profile(config_path, mainProfile)32# move_files(config_path, mainProfile)3334# If not, continue as usual:35dir_contents = config_path.glob('*')36profiles = [item for item in dir_contents if item.is_dir()]37return profiles383940def has_files(path) -> bool:41files = path.glob('*.*')4243filtered_files = filter_files(files)4445if filtered_files:46return True47return False484950def filter_files(files) -> list:51# Check for `config.json` file:52filtered_files = [file for file in files if file.name != configFile]53return filtered_files545556def move_files(path, dir_name: str):57files = path.glob('*.*')58filtered_files = filter_files(files)5960for file in filtered_files:61file.rename(file.parent / dir_name / file.name)626364def change_profile():65print('Current profiles:')66profile = get_profile_prompt(print_profiles())6768update_config(mainProfile, profile)6970print(f'\033[32mSuccessfully changed profile to\033[0m {profile}')717273def delete_profile():74print('Current profiles:')75profile = get_profile_prompt(print_profiles())7677if profile == get_current_profile():78raise OSError(79'You cannot delete a profile that you\'re currently using')8081p = get_profile_path() / profile82shutil.rmtree(p)8384print(f'\033[32mSuccessfully deleted\033[0m {profile}')858687def create_profile(path, dir_name: str):88dir_path = path / dir_name8990if not dir_path.is_dir():91dir_path.mkdir(parents=True, exist_ok=False)9293print(f'\033[32mSuccessfully created\033[0m {dir_name}')949596def edit_profile_name(old_profile_name: str, new_profile_name: str):97profiles = get_profiles()9899for profile in profiles:100if profile.stem == old_profile_name:101profile.rename(profile.parent / new_profile_name)102103print(104f"\033[32mSuccessfully changed\033[0m '{old_profile_name}' \033[32mto\033[0m '{new_profile_name}'")105106107def print_profiles() -> list:108profile_names = [profile.stem for profile in get_profiles()]109110profile_fmt = 'Profile: \033[36m{}\033[0m'111for name in profile_names:112print(profile_fmt.format(name))113114return profile_names115116117def get_current_profile():118config = read_config()119return config['config'][mainProfile]120121122def print_current_profile():123get_profiles()124125current_profile = get_current_profile()126print('Using profile: \033[36m{}\033[0m'.format(current_profile))127128129