Added counter FMN polls

This commit is contained in:
localhost_frssoft 2022-10-02 19:27:00 +03:00
parent 40f88d4e7e
commit de6c3eb8fa
2 changed files with 16 additions and 6 deletions

View file

@ -36,6 +36,11 @@ def get_already_watched(original_name=None, ru_name=None, year=None):
else:
return False
def get_count_all_watched_movies():
return len(c.execute('SELECT * FROM watched_movies').fetchall())
def get_already_suggested(acct, original_name, ru_name, year):
already_suggested = c.execute('''SELECT * FROM poll
WHERE (original_name = (?) OR ru_name = (?)) COLLATE NOCASE

View file

@ -1,18 +1,21 @@
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_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, get_count_all_watched_movies
from collections import Counter
from loguru import logger
import time
text_create_poll = '''Друзья, голосование за следующий Fediverse Movie Night объявляю открытым!
def text_create_poll():
count_poll = get_count_all_watched_movies()
text_poll = f'''Друзья, {count_poll} голосование за следующий Fediverse Movie Night объявляю открытым!
Ставки сделаны, ставок больше нет
'''.replace('\t', '')
return text_poll
def create_poll_movies(text=text_create_poll, poll_expires=345600):
def create_poll_movies(text=text_create_poll(), poll_expires=345600):
formated_poll_options = []
raw_poll = get_movies_for_poll()
for i in raw_poll:
@ -28,6 +31,7 @@ def create_poll_movies(text=text_create_poll, poll_expires=345600):
if len(poll_option_string) >= 200:
poll_option_string = poll_option_string[0:199] # Обрезка на 200 символов.
formated_poll_options.append(poll_option_string)
poll_status_id = post_status(text, None, formated_poll_options,
poll_expires=poll_expires, attachments=[upload_attachment('src/FMN.png')])
logger.success('Голосовалка создана')
@ -71,7 +75,8 @@ def get_winner_movie(poll_status_id=str):
win_variant = f"{orig_name}, {year}"
if orig_name is None:
win_variant = f"{ru_name}, {year}"
text_winned = f"Голосование завершилось! Победил вариант предложенный @{acct_suggested}:\n{win_variant}"
expired_poll_count = get_count_all_watched_movies() - 1
text_winned = f"{expired_poll_count} голосование завершилось! Победил вариант предложенный @{acct_suggested}:\n{win_variant}"
logger.success("Победил " + str(movie))
post_status(text_winned, attachments=[upload_attachment('src/FMN.png')])