From 7930d5d996723b95139295e7e237423c74682b4e Mon Sep 17 00:00:00 2001 From: localhost_frssoft Date: Thu, 4 Jul 2024 14:59:47 +0300 Subject: [PATCH] try automatically run thread if hour is 0 --- src/fedi_api.py | 4 ++-- src/listener_mention.py | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/fedi_api.py b/src/fedi_api.py index 0a18c99..20764cf 100644 --- a/src/fedi_api.py +++ b/src/fedi_api.py @@ -80,7 +80,7 @@ def get_status(status_id): logger.info(f'Retrying get status {status_id}') -def post_status(text, reply_to_status_id=None, poll_options=None, poll_expires=345600, attachments=None): +def post_status(text, reply_to_status_id=None, poll_options=None, poll_expires=345600, attachments=None, visibility='unlisted'): poll = None if poll_options is not None: poll = { @@ -91,7 +91,7 @@ def post_status(text, reply_to_status_id=None, poll_options=None, poll_expires=3 params = { "status": text, "in_reply_to_id": reply_to_status_id, - "visibility": "unlisted", + "visibility": visibility, "content_type": "text/plain", "language": "ru", "poll": poll diff --git a/src/listener_mention.py b/src/listener_mention.py index d1d2e46..91d1fe8 100644 --- a/src/listener_mention.py +++ b/src/listener_mention.py @@ -58,6 +58,33 @@ def get_control_mention(): time.sleep(0.2) mark_as_read_notification(i['id']) + states_stor.states['max_mute_time'] = int(max_mute_time) + states_stor.states['stop_thread_scan'] = int(stop_thread_scan) + states_stor.states['last_thread_id'] = st_id + write_states(states_stor.states) + break + if now_hour == 0: + logger.warning(f'Автоматический триггер в полночи сработал') + st_date = time_now + thread_created_at = dateutilparse(st_date) + + delta = relativedelta(hour=hour_poll_posting, minute=0, second=0, weekday=TU(1)) + stop_thread_scan = thread_created_at + delta + movies_accept_time = stop_thread_scan.strftime('%H:%M %d.%m.%Y по Москве') + stop_thread_scan = time.mktime(time.struct_time(stop_thread_scan.timetuple())) + + if now_week == 6: # Фикс стыков двух недель. Если вс, то расчитываем на следующую неделю + next_week = 2 + else: + next_week = 1 + next_movie_watching_delta = relativedelta(hour=fmn_next_watching_hour, minute=0, second=0, weekday=SU(next_week)) + next_movie_watching = time_now + next_movie_watching_delta + max_mute_time = time.mktime(time.struct_time(next_movie_watching.timetuple())) # Глушение до следующего сеанса FMN. + next_movie_watching = next_movie_watching.strftime('%d.%m.%Y') + st_id = post_status(start_collect_movies_text(movies_accept_time, next_movie_watching) + '\n\n@rf@mastodon.ml', None, attachments=[upload_attachment('src/FMN.webp')], "public")['id'] + + time.sleep(0.2) + states_stor.states['max_mute_time'] = int(max_mute_time) states_stor.states['stop_thread_scan'] = int(stop_thread_scan) states_stor.states['last_thread_id'] = st_id