-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaesthetic_prioritizing.py
More file actions
157 lines (119 loc) · 5.09 KB
/
aesthetic_prioritizing.py
File metadata and controls
157 lines (119 loc) · 5.09 KB
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import os
import sys
import time
import warnings
import time
import scratchattach as sa
warnings.filterwarnings('ignore', category=sa.LoginDataWarning)
warnings.filterwarnings('ignore', category=sa.GetAuthenticationWarning)
pswd = os.environ.get("PASS") #'PASS' is an env secret in the workflow, not on this device
usnm = "Boss_1s"
class ProjectNotFound(Exception):
"""Custom exception raised when a project is not found."""
def __init__(self, item_id, message="Project ID of the following was not found"):
self.item_id = item_id
self.message = f"{message}: {item_id}"
super().__init__(self.message)
class StudioNotFound(Exception):
"""Custom exception raised when a studio is not found."""
def __init__(self, item_id, message="Studio ID of the following was not found"):
self.item_id = item_id
self.message = f"{message}: {item_id}"
super().__init__(self.message)
fav_project_ids = []
fav_studios_ids = []
def favorites():
global fav_project_ids
# Get the list of favorited projects
favorited_projects = sa.get_user(usnm).favorites()
# Create an empty list to store the project IDs
fav_project_ids = []
# Iterate through the favorited projects and extract their IDs
for project in favorited_projects:
fav_project_ids.append(project.id)
max_atmp = 5
atmp = 0
# List of project IDs you want to bring to the top
project_ids_to_prioritize = [1193158560, 1193158559, 1193158558, 1193158567, 1193158568] # Replace with actual project IDs
studio_ids_to_prioritize = [50609120, 50609126, 50609128, 50609129] # Replace with actual studio IDs
def prioritize(attempt: int, maxAttempts: int):
global atmp
favorites()
try:
os.system("echo " + f"Prioritizing: Attempt {attempt + 1}")
if attempt >= maxAttempts:
raise ValueError("Process failed, and the maximum attempt value has been reached. Exiting.")
if project_ids_to_prioritize[::-1] == fav_project_ids[:len(project_ids_to_prioritize)]:
os.system("echo " + "Projects already on top. No prioritizing needed.")
return
session = sa.login(usnm, pswd)# Log in to your Scratch account
user = session.connect_user(usnm)# Get the user object for your account
for project_id in project_ids_to_prioritize:
project = session.connect_project(project_id)
if project is None:
raise ProjectNotFound(project_id)
# Check if the project is already favorited by you
if project.id in fav_project_ids:
# Unfavorite the project
project.unfavorite()
os.system("echo " + f"Unfavorited project {project_id}")
time.sleep(45)
os.system("echo " + f"Favorited project {project_id} to move it to the top")
else:
os.system("echo " + f"Favorited project {project_id} because it was never favorited")
# Favorite the project again to move it to the top
project.favorite()
time.sleep(45)
except ValueError as e:
os.system("echo " + str(e))
sys.exit(1)
except ProjectNotFound as e:
os.system("echo " + f"{e}. Retrying script")
atmp=atmp+1
prioritize(atmp, max_atmp)
except Exception as e:
os.system("echo " + f"Process failed, retying. Error: {e}")
atmp=atmp+1
prioritize(atmp, max_atmp)
def prioritize_studio(attempt: int, maxAttempts: int):
global atmp
try:
os.system("echo " + f"Prioritizing: Attempt {attempt + 1}")
if attempt >= maxAttempts:
raise ValueError("Process failed, and the maximum attempt value has been reached. Exiting.")
for studio_id in studio_ids_to_prioritize:
studio = session.connect_studio(studio_id)
if studio is None:
raise StudioNotFound(studio_id)
# Unfavorite the project
studio.unfollow()
os.system("echo " + f"Unfollowed stuido {studio_id}")
time.sleep(35)
os.system("echo " + f"Followed studio {studio_id} to move it to the top")
# Favorite the studio again to move it to the top
studio.follow()
time.sleep(45)
except ValueError as e:
os.system("echo " + str(e))
sys.exit(1)
except StudioNotFound as e:
os.system("echo " + f"{e}. Retrying script")
atmp=atmp+1
prioritize_studio(atmp, max_atmp)
except Exception as e:
os.system("echo " + f"Process failed, retying. Error: {e}")
atmp=atmp+1
prioritize_studio(atmp, max_atmp)
#-----#
max_atmp = 5
atmp = 0
try:
prioritize(atmp, max_atmp)
finally:
os.system("echo " + "Prioritized projects in your favorite list.")
#max_atmp = 5
#atmp = 0
#try:
# prioritize_studio(atmp, max_atmp)
#finally:
# os.system("echo " + "Prioritized studios in your favorite list.")