mirror of
https://git.phreedom.club/localhost_frssoft/FMN_bot.git
synced 2024-11-24 20:50:58 +01:00
Added counter FMN polls
This commit is contained in:
parent
40f88d4e7e
commit
de6c3eb8fa
|
@ -36,6 +36,11 @@ def get_already_watched(original_name=None, ru_name=None, year=None):
|
||||||
else:
|
else:
|
||||||
return False
|
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):
|
def get_already_suggested(acct, original_name, ru_name, year):
|
||||||
already_suggested = c.execute('''SELECT * FROM poll
|
already_suggested = c.execute('''SELECT * FROM poll
|
||||||
WHERE (original_name = (?) OR ru_name = (?)) COLLATE NOCASE
|
WHERE (original_name = (?) OR ru_name = (?)) COLLATE NOCASE
|
||||||
|
|
|
@ -1,18 +1,21 @@
|
||||||
from src.fedi_api import get_status, post_status, upload_attachment
|
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, get_count_all_watched_movies
|
||||||
from collections import Counter
|
from collections import Counter
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
import time
|
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', '')
|
'''.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 = []
|
formated_poll_options = []
|
||||||
raw_poll = get_movies_for_poll()
|
raw_poll = get_movies_for_poll()
|
||||||
for i in raw_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:
|
if len(poll_option_string) >= 200:
|
||||||
poll_option_string = poll_option_string[0:199] # Обрезка на 200 символов.
|
poll_option_string = poll_option_string[0:199] # Обрезка на 200 символов.
|
||||||
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.success('Голосовалка создана')
|
logger.success('Голосовалка создана')
|
||||||
|
@ -71,7 +75,8 @@ def get_winner_movie(poll_status_id=str):
|
||||||
win_variant = f"{orig_name}, {year}"
|
win_variant = f"{orig_name}, {year}"
|
||||||
if orig_name is None:
|
if orig_name is None:
|
||||||
win_variant = f"{ru_name}, {year}"
|
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))
|
logger.success("Победил " + str(movie))
|
||||||
post_status(text_winned, attachments=[upload_attachment('src/FMN.png')])
|
post_status(text_winned, attachments=[upload_attachment('src/FMN.png')])
|
||||||
|
|
Loading…
Reference in New Issue
Block a user