mirror of
https://git.phreedom.club/localhost_frssoft/FMN_bot.git
synced 2024-11-24 18:00:56 +01:00
import cleanup and retries for context thread; pep8
This commit is contained in:
parent
6414cd863b
commit
81c13c3c96
|
@ -1,6 +1,5 @@
|
|||
from config import instance
|
||||
import time
|
||||
import json
|
||||
import requests
|
||||
from loguru import logger
|
||||
|
||||
|
@ -35,7 +34,6 @@ def get_notifications():
|
|||
logger.info('Retrying get notificatios...')
|
||||
|
||||
|
||||
|
||||
def mark_as_read_notification(id_notification):
|
||||
success = 0
|
||||
while success == 0:
|
||||
|
@ -51,6 +49,7 @@ def mark_as_read_notification(id_notification):
|
|||
|
||||
|
||||
def get_status_context(status_id):
|
||||
retry = 0
|
||||
success = 0
|
||||
while success == 0:
|
||||
try:
|
||||
|
@ -58,10 +57,13 @@ def get_status_context(status_id):
|
|||
r.raise_for_status()
|
||||
success = 1
|
||||
return r.json()
|
||||
except:
|
||||
except Exception as E:
|
||||
logger.exception(f'Ошибка получения контекста треда {status_id}')
|
||||
time.sleep(30)
|
||||
logger.info('Повторный запрос треда...')
|
||||
retry += 1
|
||||
if retry > 5:
|
||||
raise IOError(f'Фетчинг треда поломан! {E}')
|
||||
|
||||
|
||||
def get_status(status_id):
|
||||
|
@ -78,7 +80,6 @@ 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):
|
||||
poll = None
|
||||
if poll_options is not None:
|
||||
|
@ -136,4 +137,3 @@ def mute_user(acct_id=str, acct=str, duration=None):
|
|||
logger.exception(f'Ошибка глушения {acct}')
|
||||
time.sleep(5)
|
||||
logger.info(f'Повторное глушение {acct}...')
|
||||
|
||||
|
|
|
@ -3,13 +3,10 @@ from src.fedi_api import get_status_context, get_status, post_status, mute_user
|
|||
from src.kinopoisk_api import get_kinopoisk_movie_to_imdb
|
||||
from src.imdb_datasets_worker import get_title_by_id
|
||||
from src.fmn_database import add_movie_to_poll, get_already_watched, get_suggested_movies_count
|
||||
from src.fmn_states_db import states_stor, write_states
|
||||
from src.fmn_states_db import states_stor
|
||||
from src.fmn_poll import create_poll_movies, get_winner_movie
|
||||
import re
|
||||
import time
|
||||
from datetime import datetime
|
||||
from dateutil.parser import parse as dateutilparse
|
||||
from dateutil.relativedelta import relativedelta, TU
|
||||
from collections import Counter
|
||||
from loguru import logger
|
||||
|
||||
|
@ -123,7 +120,6 @@ def scan_context_thread():
|
|||
fail_limit[acct] += 1
|
||||
continue
|
||||
|
||||
|
||||
for movie in suggested_movies:
|
||||
logger.debug(str(movie))
|
||||
if movie[index_type] == "404":
|
||||
|
@ -155,7 +151,7 @@ def scan_context_thread():
|
|||
fail_limit[acct] += 1
|
||||
break
|
||||
|
||||
if get_already_watched(name, name_ru, year) == True:
|
||||
if get_already_watched(name, name_ru, year) is True:
|
||||
message_writer.append(f"ℹ️ Этот фильм уже был на FMN: {movie_string}")
|
||||
logger.info(f'Попытка предложить уже просмотренный фильм: {acct} {name} {name_ru} {year}')
|
||||
fail_limit[acct] += 1
|
||||
|
@ -181,5 +177,3 @@ def scan_context_thread():
|
|||
post_status('\n'.join(message_writer) + message, id_st)
|
||||
|
||||
time.sleep(30)
|
||||
|
||||
|
||||
|
|
|
@ -2,7 +2,8 @@ from src.fedi_api import get_notifications, mark_as_read_notification, post_stat
|
|||
from src.fmn_states_db import write_states, states_stor
|
||||
from config import admins_bot, limit_movies_per_user, limit_all_movies_poll, hour_poll_posting, fmn_next_watching_hour
|
||||
|
||||
import threading, time
|
||||
import threading
|
||||
import time
|
||||
from datetime import datetime
|
||||
from dateutil.parser import parse as dateutilparse
|
||||
from dateutil.relativedelta import relativedelta, TU, SU
|
||||
|
@ -19,7 +20,8 @@ def get_control_mention():
|
|||
now_hour = time_now.hour
|
||||
if now_week not in (0, 6):
|
||||
continue
|
||||
if now_week == 6 and now_hour < fmn_next_watching_hour: # Предотвращение работы в холстую до начала сеанса
|
||||
if now_week == 6 and now_hour < fmn_next_watching_hour:
|
||||
# Предотвращение работы в холстую до начала сеанса
|
||||
continue
|
||||
post_exists = states.get('last_thread_id')
|
||||
if post_exists:
|
||||
|
@ -32,7 +34,7 @@ def get_control_mention():
|
|||
seen = i['pleroma']['is_seen']
|
||||
acct_mention = i['account']['acct']
|
||||
reply_to_id = i['status']['in_reply_to_id']
|
||||
if acct_mention in admins_bot and seen == False and reply_to_id == None and now_week in (0, 6):
|
||||
if acct_mention in admins_bot and seen is False and reply_to_id is None and now_week in (0, 6):
|
||||
logger.success(f'Найдено упоминание от {acct_mention}')
|
||||
st_id = i['status']['id']
|
||||
st_date = i['status']['created_at']
|
||||
|
@ -83,7 +85,7 @@ def start_collect_movies_text(movies_accept_time=str, next_movie_watching=str):
|
|||
'''.replace('\t', '')
|
||||
return text
|
||||
|
||||
|
||||
def run_scan_notif():
|
||||
scan_notif = threading.Thread(target=get_control_mention, daemon=True)
|
||||
scan_notif.start()
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user