mirror of
https://gitea.phreedom.club/localhost_frssoft/FMN_bot
synced 2024-11-22 20:59:24 +02:00
Add change thread context on the fly
This commit is contained in:
parent
3f923cf2a6
commit
84870c9d7c
|
@ -5,11 +5,12 @@ from dateutil.relativedelta import relativedelta, TU
|
||||||
|
|
||||||
import re
|
import re
|
||||||
import logging
|
import logging
|
||||||
from config import hour_poll_posting, bot_acct
|
from config import hour_poll_posting, bot_acct, instance
|
||||||
from src.fedi_api import get_status_context, get_status, post_status
|
from src.fedi_api import get_status_context, get_status, post_status
|
||||||
from src.kinopoisk_api import get_kinopoisk_movie
|
from src.kinopoisk_api import get_kinopoisk_movie
|
||||||
from src.imdb_datasets_worker import get_title_by_id
|
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_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
|
||||||
|
|
||||||
logger = logging.getLogger('thread_listener')
|
logger = logging.getLogger('thread_listener')
|
||||||
|
@ -33,29 +34,28 @@ def parse_links_imdb(text=str):
|
||||||
|
|
||||||
|
|
||||||
def scan_context_thread():
|
def scan_context_thread():
|
||||||
status_id = None
|
|
||||||
poll_created = False
|
|
||||||
while True:
|
while True:
|
||||||
|
status_id = get_state('last_thread_id')
|
||||||
|
poll_created = get_state('poll_status_id')
|
||||||
|
flag_scan = 0
|
||||||
time_now = time.time()
|
time_now = time.time()
|
||||||
while status_id == None:
|
while status_id is None:
|
||||||
try:
|
status_id = get_state('last_thread_id')
|
||||||
with open('last_thread_id', mode='rt') as file:
|
if status_id and flag_scan == 0:
|
||||||
status_id = file.read().replace('\n', '')
|
|
||||||
thread_created_at = get_status(status_id)['created_at']
|
thread_created_at = get_status(status_id)['created_at']
|
||||||
thread_created_at = dateutilparse(thread_created_at)
|
thread_created_at = dateutilparse(thread_created_at)
|
||||||
delta = relativedelta(hour=hour_poll_posting, minute=0, second=0, weekday=TU(1))
|
delta = relativedelta(hour=hour_poll_posting, minute=0, second=0, weekday=TU(1))
|
||||||
stop_thread_scan = thread_created_at + delta
|
stop_thread_scan = thread_created_at + delta
|
||||||
logger.info('Сбор будет завершен в ' + stop_thread_scan.strftime('%c'))
|
logger.info('Сбор будет завершен в ' + stop_thread_scan.strftime('%c'))
|
||||||
stop_thread_scan = time.mktime(time.struct_time(stop_thread_scan.timetuple()))
|
stop_thread_scan = time.mktime(time.struct_time(stop_thread_scan.timetuple()))
|
||||||
except Exception as E:
|
flag_scan = 1
|
||||||
logger.exception(E)
|
|
||||||
status_id = None
|
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
if int(time_now) >= int(stop_thread_scan):
|
if int(time_now) >= int(stop_thread_scan):
|
||||||
logger.debug('Сбор завершён, сканирование треда на опоздавших')
|
logger.debug('Сбор завершён, сканирование треда на опоздавших')
|
||||||
if poll_created is False:
|
if poll_created is None:
|
||||||
create_poll_movies()
|
create_poll_movies()
|
||||||
poll_created = True
|
poll_created = get_state('poll_status_id')
|
||||||
else:
|
else:
|
||||||
endings = stop_thread_scan - time_now
|
endings = stop_thread_scan - time_now
|
||||||
logger.debug(f'Осталось до закрытия сбора: {endings}')
|
logger.debug(f'Осталось до закрытия сбора: {endings}')
|
||||||
|
@ -80,8 +80,8 @@ def scan_context_thread():
|
||||||
if parsed_result is None and parsed_result_imdb is None:
|
if parsed_result is None and parsed_result_imdb is None:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if poll_created is True:
|
if poll_created:
|
||||||
post_status('ℹ️ Приём заявок уже окончен', id_st)
|
post_status(f'ℹ️ Приём заявок уже окончен.\n\nГолосовалка здесь: https://{instance}/notice/{poll_created}', id_st)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if parsed_result is not None:
|
if parsed_result is not None:
|
||||||
|
|
Loading…
Reference in New Issue