From a26bd29e5875f1775b2f6ec27c6a59cb58971355 Mon Sep 17 00:00:00 2001 From: localhost_frssoft Date: Wed, 31 Aug 2022 22:26:58 +0300 Subject: [PATCH] Some fixes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Теперь здесь же будет вызываться проверка победившего фильма когда опрос будет окончен --- src/listener_context.py | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/listener_context.py b/src/listener_context.py index 3de6343..d2d34d9 100644 --- a/src/listener_context.py +++ b/src/listener_context.py @@ -11,7 +11,7 @@ from src.kinopoisk_api import get_kinopoisk_movie from src.imdb_datasets_worker import get_title_by_id from src.fmn_database import add_movie_to_poll, get_already_watched from src.fmn_states_db import get_state, add_state -from src.fmn_poll import create_poll_movies +from src.fmn_poll import create_poll_movies, get_winner_movie logger = logging.getLogger('thread_listener') @@ -37,27 +37,24 @@ def scan_context_thread(): while True: status_id = get_state('last_thread_id') poll_created = get_state('poll_status_id') + stop_thread_scan = get_state('stop_thread_scan') flag_scan = 0 - time_now = time.time() - while status_id is None: + time_now = int(time.time()) + while status_id is None or stop_thread_scan is None: status_id = get_state('last_thread_id') - if status_id and flag_scan == 0: - thread_created_at = get_status(status_id)['created_at'] - thread_created_at = dateutilparse(thread_created_at) - delta = relativedelta(hour=hour_poll_posting, minute=0, second=0, weekday=TU(1)) - stop_thread_scan = thread_created_at + delta - logger.info('Сбор будет завершен в ' + stop_thread_scan.strftime('%c')) - stop_thread_scan = time.mktime(time.struct_time(stop_thread_scan.timetuple())) - flag_scan = 1 + stop_thread_scan = get_state('stop_thread_scan') time.sleep(1) - if int(time_now) >= int(stop_thread_scan): + if time_now >= int(stop_thread_scan): logger.debug('Сбор завершён, сканирование треда на опоздавших') if poll_created is None: create_poll_movies() poll_created = get_state('poll_status_id') + else: + if time_now >= int(get_state('poll_expires_at')): + get_winner_movie(poll_created) else: - endings = stop_thread_scan - time_now + endings = int(stop_thread_scan) - time_now logger.debug(f'Осталось до закрытия сбора: {endings}') descendants = get_status_context(status_id)['descendants'] replyed = []