mirror of
https://gitea.phreedom.club/localhost_frssoft/FMN_bot.git
synced 2024-12-23 12:19:47 +00:00
Tie breakers checked
This commit is contained in:
parent
8f235b2cc6
commit
9708d36e5d
@ -1,7 +1,9 @@
|
||||
from collections import Counter
|
||||
from src.fedi_api import get_status, post_status
|
||||
from src.fmn_database import get_movies_for_poll, write_votes, read_votes, mark_as_watched_movie, get_already_watched, rewrite_db
|
||||
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 collections import Counter
|
||||
import logging
|
||||
import time
|
||||
|
||||
logger = logging.getLogger('fmn_poll')
|
||||
|
||||
@ -28,13 +30,13 @@ def create_poll_movies(text=text_create_poll, poll_expires=345600):
|
||||
|
||||
poll_status_id = post_status(text, None, formated_poll_options, poll_expires=poll_expires)['id']
|
||||
logger.info('Голосовалка создана')
|
||||
with open('poll_status_id', mode='wt') as file:
|
||||
file.write(poll_status_id)
|
||||
add_state('poll_expires_at', int(time.time()) + poll_expires)
|
||||
add_state('poll_status_id', poll_status_id)
|
||||
return poll_status_id
|
||||
|
||||
|
||||
def get_winner_movie(poll_status_id=str):
|
||||
'''Отмечаем победивший фильм на голосовании как просмотренный и постим об этом'''
|
||||
'''Отмечаем победивший фильм на голосовании как просмотренный или постим tie breaker'''
|
||||
votes_counters = []
|
||||
status_with_poll = get_status(poll_status_id)
|
||||
poll = status_with_poll['poll']
|
||||
@ -54,15 +56,24 @@ def get_winner_movie(poll_status_id=str):
|
||||
if len(winned_movies) > 1:
|
||||
logger.warning('Будет создан tie breaker')
|
||||
rewrite_db(winned_movies)
|
||||
create_tie_breaker()
|
||||
if get_state('tie_breaker'):
|
||||
create_tie_breaker(2)
|
||||
else:
|
||||
create_tie_breaker()
|
||||
else:
|
||||
movie = winned_movies[0]
|
||||
logger.warning("Победил " + str(movie))
|
||||
mark_as_watched_movie(movie[1], movie[2], movie[3])
|
||||
clear_all_states()
|
||||
reset_poll()
|
||||
|
||||
|
||||
def create_tie_breaker():
|
||||
tie_poll = create_poll_movies("TIE BREAKER!!!", 8*60*60)
|
||||
time.sleep(8*60*60)
|
||||
get_winner_movie(tie_poll)
|
||||
def create_tie_breaker(count_tie=1):
|
||||
'''Создание tie breaker'''
|
||||
if count_tie == 1:
|
||||
add_state('tie_breaker', 1)
|
||||
poll_expires = 8*60*60
|
||||
else:
|
||||
poll_expires = 4*60*60
|
||||
tie_poll = create_poll_movies("[Чисто проверить как отрабатывают тай брекеры и в целом препарирование опросов] TIE BREAKER!!!", poll_expires)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user