Compare commits

...

3 commits

9 changed files with 21 additions and 34 deletions

View file

@ -13,5 +13,5 @@ max_fail_limit = 4 # Игнорировать предложения польз
hour_poll_posting = 16 # Час в который будет создан пост с голосовалкой (и завершение сбора) hour_poll_posting = 16 # Час в который будет создан пост с голосовалкой (и завершение сбора)
fmn_next_watching_hour = 21 # Час начала киносеанса fmn_next_watching_hour = 21 # Час начала киносеанса
logger_default_level = 10 # Уровень логгирования 10 - DEBUG, 20 - INFO, 30 - WARN logger_default_level = 'DEBUG' # Уровень логгирования TRACE, DEBUG, INFO, SUCCESS, WARNING, ERROR, CRITICAL

View file

@ -1,12 +1,14 @@
from src import listener_context, listener_mention, imdb_datasets_worker from src import listener_context, listener_mention, imdb_datasets_worker
from config import logger_default_level from config import logger_default_level
import logging from loguru import logger
import time import time
import sys
def main(): def main():
logging.basicConfig(level=logger_default_level) logger.remove()
logger.add(sink=sys.stderr, level=logger_default_level)
listener_mention.run_scan_notif() # Слушаем упоминания в фоне listener_mention.run_scan_notif() # Слушаем упоминания в фоне
time.sleep(1) time.sleep(1)

View file

@ -1,3 +1,4 @@
loguru
requests requests
python-dateutil python-dateutil

View file

@ -2,9 +2,7 @@ from config import instance
import time import time
import json import json
import requests import requests
import logging from loguru import logger
logger = logging.getLogger('fedi_api')
instance_point = f"https://{instance}/api/v1" instance_point = f"https://{instance}/api/v1"

View file

@ -1,10 +1,8 @@
import sqlite3 import sqlite3
import logging from loguru import logger
from config import limit_movies_per_user from config import limit_movies_per_user
logger = logging.getLogger('fmn_db')
conn = sqlite3.connect("fmn.sqlite") conn = sqlite3.connect("fmn.sqlite")
c = conn.cursor() c = conn.cursor()

View file

@ -2,10 +2,9 @@ from src.fedi_api import get_status, post_status, upload_attachment
from src.fmn_states_db import add_state, get_state, clear_all_states from src.fmn_states_db import add_state, get_state, clear_all_states
from src.fmn_database import get_movies_for_poll, write_votes, read_votes, mark_as_watched_movie, get_already_watched, rewrite_db, reset_poll from src.fmn_database import get_movies_for_poll, write_votes, read_votes, mark_as_watched_movie, get_already_watched, rewrite_db, reset_poll
from collections import Counter from collections import Counter
import logging from loguru import logger
import time import time
logger = logging.getLogger('fmn_poll')
text_create_poll = '''Друзья, голосование за следующий Fediverse Movie Night объявляю открытым! text_create_poll = '''Друзья, голосование за следующий Fediverse Movie Night объявляю открытым!
@ -29,7 +28,7 @@ def create_poll_movies(text=text_create_poll, poll_expires=345600):
formated_poll_options.append(poll_option_string) formated_poll_options.append(poll_option_string)
poll_status_id = post_status(text, None, formated_poll_options, poll_status_id = post_status(text, None, formated_poll_options,
poll_expires=poll_expires, attachments=[upload_attachment('src/FMN.png')]) poll_expires=poll_expires, attachments=[upload_attachment('src/FMN.png')])
logger.info('Голосовалка создана') logger.success('Голосовалка создана')
add_state('poll_expires_at', int(time.time()) + poll_expires) add_state('poll_expires_at', int(time.time()) + poll_expires)
add_state('poll_status_id', poll_status_id['id']) add_state('poll_status_id', poll_status_id['id'])
return poll_status_id return poll_status_id
@ -77,7 +76,7 @@ def get_winner_movie(poll_status_id=str):
{win_variant} {win_variant}
'''.replace('\t', '') '''.replace('\t', '')
logger.warning("Победил " + str(movie)) logger.success("Победил " + str(movie))
post_status(text_winned, attachments=[upload_attachment('src/FMN.png')]) post_status(text_winned, attachments=[upload_attachment('src/FMN.png')])
clear_all_states() clear_all_states()
reset_poll() reset_poll()

View file

@ -1,9 +1,7 @@
import sqlite3 import sqlite3
import logging from loguru import logger
logger = logging.getLogger('fmn_states_database')
conn = sqlite3.connect("fmn_states.sqlite", check_same_thread=False) conn = sqlite3.connect("fmn_states.sqlite", check_same_thread=False)
c = conn.cursor() c = conn.cursor()
@ -23,7 +21,7 @@ def add_state(key, value):
def get_state(key): def get_state(key):
'''Получение стейта по ключу''' '''Получение стейта по ключу'''
logger.debug(f'Запрошен стейт {key}') logger.trace(f'Запрошен стейт {key}')
value = c.execute("SELECT value FROM states WHERE key = (?)", (key,)).fetchone() value = c.execute("SELECT value FROM states WHERE key = (?)", (key,)).fetchone()
if value: if value:
return value[0] return value[0]

View file

@ -84,20 +84,14 @@ def convert_datasets_to_db():
def get_title_by_id(films_ids=list): def get_title_by_id(films_ids=list):
tt_list = [] tt_list = c.executemany("SELECT * FROM titles WHERE tt_id = (?)", films_ids).fetchall()
for i in films_ids: if tt_list != []:
tt_film = c.execute("SELECT * FROM titles WHERE tt_id = (?)", (i,)).fetchone() return tt_list
tt_list.append(tt_film)
return tt_list
def get_title_by_names_and_year(film_names=list): def get_title_by_names_and_year(film_names=list):
tt_list = [] tt_list = c.executemany('''SELECT * FROM titles
for i in film_names:
tt_film = c.execute('''SELECT * FROM titles
WHERE (original_name = (?) OR ru_name = (?)) WHERE (original_name = (?) OR ru_name = (?))
AND year = (?)''', i).fetchone() AND year = (?)''', film_names).fetchall()
if tt_film:
tt_list.append(tt_film)
if tt_list != []: if tt_list != []:
return tt_list return tt_list

View file

@ -5,16 +5,13 @@ 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_database import add_movie_to_poll, get_already_watched, get_suggested_movies_count
from src.fmn_states_db import get_state, add_state from src.fmn_states_db import get_state, add_state
from src.fmn_poll import create_poll_movies, get_winner_movie from src.fmn_poll import create_poll_movies, get_winner_movie
import re
import time import time
from datetime import datetime from datetime import datetime
from dateutil.parser import parse as dateutilparse from dateutil.parser import parse as dateutilparse
from dateutil.relativedelta import relativedelta, TU from dateutil.relativedelta import relativedelta, TU
from collections import Counter from collections import Counter
import re from loguru import logger
import logging
logger = logging.getLogger('thread_listener')
def parse_links(text=str): def parse_links(text=str):
@ -149,7 +146,7 @@ def scan_context_thread():
add_result = add_movie_to_poll(acct, name, name_ru, year) add_result = add_movie_to_poll(acct, name, name_ru, year)
if add_result == 0: if add_result == 0:
message_writer.append(f"✅ Принято: {movie_string}") message_writer.append(f"✅ Принято: {movie_string}")
logger.info(f'Предложение от {acct} принято: {name} {name_ru} {year}') logger.success(f'Предложение от {acct} принято: {name} {name_ru} {year}')
success = True success = True
elif add_result == 1: elif add_result == 1:
message_writer.append("❌ Этот фильм уже был предложен") message_writer.append("❌ Этот фильм уже был предложен")