Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
taux1c
GitHub Repository: taux1c/onlyfans-scraper
Path: blob/main/onlyfans_scraper/utils/profiles.py
961 views
1
r"""
2
_ __
3
___ _ __ | | _ _ / _| __ _ _ __ ___ ___ ___ _ __ __ _ _ __ ___ _ __
4
/ _ \ | '_ \ | || | | || |_ / _` || '_ \ / __| _____ / __| / __|| '__| / _` || '_ \ / _ \| '__|
5
| (_) || | | || || |_| || _|| (_| || | | |\__ \|_____|\__ \| (__ | | | (_| || |_) || __/| |
6
\___/ |_| |_||_| \__, ||_| \__,_||_| |_||___/ |___/ \___||_| \__,_|| .__/ \___||_|
7
|___/ |_|
8
"""
9
10
import pathlib
11
import shutil
12
13
from .config import read_config, update_config
14
from .prompts import get_profile_prompt
15
from ..constants import configPath, configFile, mainProfile
16
configPath = '.config/onlyfans-scraper'
17
18
19
def get_profile_path():
20
config_path = pathlib.Path.home() / configPath
21
return config_path
22
23
24
def get_profiles() -> list:
25
config_path = get_profile_path()
26
27
# (This block of code should be removed in the 1.0 release)
28
#
29
# If user upgraded from an older version of onlyfans-scraper or if the user
30
# has an auth.json or models.db file in the config_path:
31
# if has_files(config_path):
32
# create_profile(config_path, mainProfile)
33
# move_files(config_path, mainProfile)
34
35
# If not, continue as usual:
36
dir_contents = config_path.glob('*')
37
profiles = [item for item in dir_contents if item.is_dir()]
38
return profiles
39
40
41
def has_files(path) -> bool:
42
files = path.glob('*.*')
43
44
filtered_files = filter_files(files)
45
46
if filtered_files:
47
return True
48
return False
49
50
51
def filter_files(files) -> list:
52
# Check for `config.json` file:
53
filtered_files = [file for file in files if file.name != configFile]
54
return filtered_files
55
56
57
def move_files(path, dir_name: str):
58
files = path.glob('*.*')
59
filtered_files = filter_files(files)
60
61
for file in filtered_files:
62
file.rename(file.parent / dir_name / file.name)
63
64
65
def change_profile():
66
print('Current profiles:')
67
profile = get_profile_prompt(print_profiles())
68
69
update_config(mainProfile, profile)
70
71
print(f'\033[32mSuccessfully changed profile to\033[0m {profile}')
72
73
74
def delete_profile():
75
print('Current profiles:')
76
profile = get_profile_prompt(print_profiles())
77
78
if profile == get_current_profile():
79
raise OSError(
80
'You cannot delete a profile that you\'re currently using')
81
82
p = get_profile_path() / profile
83
shutil.rmtree(p)
84
85
print(f'\033[32mSuccessfully deleted\033[0m {profile}')
86
87
88
def create_profile(path, dir_name: str):
89
dir_path = path / dir_name
90
91
if not dir_path.is_dir():
92
dir_path.mkdir(parents=True, exist_ok=False)
93
94
print(f'\033[32mSuccessfully created\033[0m {dir_name}')
95
96
97
def edit_profile_name(old_profile_name: str, new_profile_name: str):
98
profiles = get_profiles()
99
100
for profile in profiles:
101
if profile.stem == old_profile_name:
102
profile.rename(profile.parent / new_profile_name)
103
104
print(
105
f"\033[32mSuccessfully changed\033[0m '{old_profile_name}' \033[32mto\033[0m '{new_profile_name}'")
106
107
108
def print_profiles() -> list:
109
profile_names = [profile.stem for profile in get_profiles()]
110
111
profile_fmt = 'Profile: \033[36m{}\033[0m'
112
for name in profile_names:
113
print(profile_fmt.format(name))
114
115
return profile_names
116
117
118
def get_current_profile():
119
config = read_config()
120
return config['config'][mainProfile]
121
122
123
def print_current_profile():
124
get_profiles()
125
126
current_profile = get_current_profile()
127
print('Using profile: \033[36m{}\033[0m'.format(current_profile))
128
129