@@ -34,17 +34,17 @@ def process_like(posts=None, model_id=None, username=None, **kwargs):
34
34
progress_utils .switch_api_progress ()
35
35
progress_updater .update_activity_task (description = like_str .format (name = username ))
36
36
logging .getLogger ("shared" ).warning (like_str .format (name = username ))
37
- like_result = like (model_id , username , posts )
38
- return like_result
37
+ like (model_id , username , posts )
38
+ manager . Manager . stats_manager . update_stats ( username , "like" , posts )
39
39
40
40
41
41
@exit .exit_wrapper
42
42
def process_unlike (posts = None , model_id = None , username = None , ** kwargs ):
43
43
progress_utils .switch_api_progress ()
44
44
progress_updater .update_activity_task (description = unlike_str .format (name = username ))
45
45
logging .getLogger ("shared" ).warning (unlike_str .format (name = username ))
46
- unlike_result = unlike (model_id , username , posts )
47
- return unlike_result
46
+ unlike (model_id , username , posts )
47
+ manager . Manager . stats_manager . update_stats ( username , "unlike" , posts )
48
48
49
49
50
50
def get_posts_for_unlike (post ):
@@ -102,59 +102,18 @@ def _like(model_id, username, posts: list, like_action: bool):
102
102
]
103
103
max_duration = of_env .getattr ("MAX_SLEEP_DURATION_LIKE" )
104
104
min_duration = of_env .getattr ("MIN_SLEEP_DURATION_LIKE" )
105
- failed = 0
106
- post = 0
107
- liked = 0
108
105
109
106
for _ , func in enumerate (tasks ):
110
107
out = func ()
111
- post += 1
112
- # no sleep if cache
113
- if out == 0 :
114
- sleep_duration = 0
115
- # random sleep else
116
- else :
117
- sleep_duration = random .uniform (min_duration , max_duration )
118
- # if toggled once
108
+ sleep_duration = random .uniform (min_duration , max_duration )
119
109
if out == 1 :
120
- liked += 1
121
110
progress_updater .increment_like_task (task2 )
122
- # if failed
123
- elif out == 3 :
124
- failed += 1
125
111
progress_updater .increment_like_task (task )
126
112
time .sleep (sleep_duration )
127
113
progress_updater .remove_like_task (task )
128
114
progress_updater .remove_like_task (task2 )
129
- return get_final_like_log (like_action , username , failed , post , liked )
130
115
131
116
132
- def get_final_like_log (like_action , username , failed , post , liked ):
133
- title = "Liked" if like_action else "Unliked"
134
- action = title .lower ()
135
- unchanged = post - failed - liked
136
-
137
- liked_changed_log = (
138
- f"{ liked } post changed to { action } "
139
- if liked == 0
140
- else f"[green]{ liked } post changed to { action } [/green]"
141
- )
142
- like_unchanged_log = (
143
- f"{ unchanged } posts not changed"
144
- if unchanged == 0
145
- else f"[yellow]{ unchanged } post not changed[/yellow]"
146
- )
147
- failed_log = "0 post failed" if failed == 0 else f"[red]{ failed } post failed[/red]"
148
- post_check_log = f"{ post } posts checked and kept at { action } "
149
-
150
- text_out = ""
151
- if post == 0 :
152
- text_out = f"[bold]\\ [{ username } ][/bold] [bold][Action { title } ][/bold] \\ [{ post_check_log } , ({ liked_changed_log } , { like_unchanged_log } ), { failed_log } ]"
153
- log .warning (text_out )
154
- else :
155
- text_out = f"[deep_sky_blue2][bold]\\ [{ username } ][/bold] [bold][Action { title } ][/bold] [[yellow]{ post_check_log } [/yellow], ({ liked_changed_log } , { like_unchanged_log } ), { failed_log } ][/deep_sky_blue2]"
156
- log .warning (text_out )
157
- return text_out
158
117
159
118
160
119
def _toggle_like_requests (c , post : Post , model_id ):
@@ -166,18 +125,17 @@ def _toggle_like_requests(c, post: Post, model_id):
166
125
favorited , id = _like_request (c , post .id , model_id )
167
126
if favorited is None :
168
127
post .mark_post_liked (success = False )
169
- out = 3
128
+ return 3
170
129
elif favorited :
171
130
log .debug (f"ID: { id } changed to liked" )
172
- out = 1
173
131
post .mark_post_liked ()
132
+ return 1
174
133
else :
175
134
log .debug (f"ID: { id } restored to liked" )
176
135
time .sleep (sleep_duration )
177
136
_like_request (c , id , model_id )
178
- out = 2
179
137
post .mark_post_liked ()
180
- return out
138
+ return 2
181
139
182
140
183
141
def _toggle_unlike_requests (c , post : Post , model_id ):
@@ -187,18 +145,17 @@ def _toggle_unlike_requests(c, post: Post, model_id):
187
145
favorited , id = _like_request (c , post .id , model_id )
188
146
if favorited is None :
189
147
post .mark_post_unliked (success = False )
190
- out = 3
148
+ return 3
191
149
elif favorited is False :
192
150
log .debug (f"ID: { id } changed to unliked" )
193
- out = 1
194
151
post .mark_post_unliked ()
152
+ return 1
195
153
else :
196
154
log .debug (f"ID: { id } restored to unlike" )
197
155
time .sleep (sleep_duration )
198
156
_like_request (c , id , model_id )
199
- out = 2
200
157
post .mark_post_unliked ()
201
- return out
158
+ return 2
202
159
203
160
204
161
def _like_request (c , id , model_id ):
0 commit comments