@@ -34,17 +34,17 @@ def process_like(posts=None, model_id=None, username=None, **kwargs):
3434 progress_utils .switch_api_progress ()
3535 progress_updater .update_activity_task (description = like_str .format (name = username ))
3636 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 )
3939
4040
4141@exit .exit_wrapper
4242def process_unlike (posts = None , model_id = None , username = None , ** kwargs ):
4343 progress_utils .switch_api_progress ()
4444 progress_updater .update_activity_task (description = unlike_str .format (name = username ))
4545 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 )
4848
4949
5050def get_posts_for_unlike (post ):
@@ -102,59 +102,18 @@ def _like(model_id, username, posts: list, like_action: bool):
102102 ]
103103 max_duration = of_env .getattr ("MAX_SLEEP_DURATION_LIKE" )
104104 min_duration = of_env .getattr ("MIN_SLEEP_DURATION_LIKE" )
105- failed = 0
106- post = 0
107- liked = 0
108105
109106 for _ , func in enumerate (tasks ):
110107 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 )
119109 if out == 1 :
120- liked += 1
121110 progress_updater .increment_like_task (task2 )
122- # if failed
123- elif out == 3 :
124- failed += 1
125111 progress_updater .increment_like_task (task )
126112 time .sleep (sleep_duration )
127113 progress_updater .remove_like_task (task )
128114 progress_updater .remove_like_task (task2 )
129- return get_final_like_log (like_action , username , failed , post , liked )
130115
131116
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
158117
159118
160119def _toggle_like_requests (c , post : Post , model_id ):
@@ -166,18 +125,17 @@ def _toggle_like_requests(c, post: Post, model_id):
166125 favorited , id = _like_request (c , post .id , model_id )
167126 if favorited is None :
168127 post .mark_post_liked (success = False )
169- out = 3
128+ return 3
170129 elif favorited :
171130 log .debug (f"ID: { id } changed to liked" )
172- out = 1
173131 post .mark_post_liked ()
132+ return 1
174133 else :
175134 log .debug (f"ID: { id } restored to liked" )
176135 time .sleep (sleep_duration )
177136 _like_request (c , id , model_id )
178- out = 2
179137 post .mark_post_liked ()
180- return out
138+ return 2
181139
182140
183141def _toggle_unlike_requests (c , post : Post , model_id ):
@@ -187,18 +145,17 @@ def _toggle_unlike_requests(c, post: Post, model_id):
187145 favorited , id = _like_request (c , post .id , model_id )
188146 if favorited is None :
189147 post .mark_post_unliked (success = False )
190- out = 3
148+ return 3
191149 elif favorited is False :
192150 log .debug (f"ID: { id } changed to unliked" )
193- out = 1
194151 post .mark_post_unliked ()
152+ return 1
195153 else :
196154 log .debug (f"ID: { id } restored to unlike" )
197155 time .sleep (sleep_duration )
198156 _like_request (c , id , model_id )
199- out = 2
200157 post .mark_post_unliked ()
201- return out
158+ return 2
202159
203160
204161def _like_request (c , id , model_id ):
0 commit comments