Compare commits

..

No commits in common. "e782cacf5a7b9b926b5deac1208dcd21fbc84ea2" and "f3ef0e45313601542ed2ab041cb0ce23665e85e9" have entirely different histories.

2 changed files with 22 additions and 57 deletions

View file

@ -25,31 +25,25 @@ def get_notifications():
def mark_as_read_notification(id_notification): def mark_as_read_notification(id_notification):
success = 0
while success == 0:
try:
r = requests.post(instance_point + f"/notifications/{id_notification}/dismiss", headers=headers) r = requests.post(instance_point + f"/notifications/{id_notification}/dismiss", headers=headers)
r.raise_for_status()
success = 1
return r.json() return r.json()
except:
logger.exception(f'Error read notification {id_notification}')
time.sleep(30)
logger.info('Retrying read notification {id_notification}...')
def get_status_context(status_id): def get_status_context(status_id):
success = 0
while success == 0:
try:
r = requests.get(instance_point + f"/statuses/{status_id}/context", headers=headers) r = requests.get(instance_point + f"/statuses/{status_id}/context", headers=headers)
r.raise_for_status() if r.status_code == 200:
success = 1
return r.json() return r.json()
except: else:
logger.exception(f'Ошибка получения контекста треда {status_id}') http_code = r.status_code
logger.error(f'Ошибка получения контекста треда {status_id}: {http_code}')
logger.error(str(r.headers))
while r.status_code != 200:
time.sleep(30) time.sleep(30)
logger.info('Повторный запрос треда...') logger.info('Повторный запрос треда...')
r = requests.get(instance_point + f"/statuses/{status_id}/context", headers=headers)
return r.json()
def get_status(status_id): def get_status(status_id):
@ -75,16 +69,8 @@ def post_status(text, reply_to_status_id=None, poll_options=None, poll_expires=3
} }
if attachments: if attachments:
params['media_ids'] = attachments params['media_ids'] = attachments
success = 0
while success == 0:
try:
r = requests.post(instance_point + "/statuses", json=params, headers=headers) r = requests.post(instance_point + "/statuses", json=params, headers=headers)
r.raise_for_status()
success = 1
return r.json() return r.json()
except:
logger.exception('Error send status, retrying...')
time.sleep(5)
def upload_attachment(file_path): def upload_attachment(file_path):
@ -102,15 +88,9 @@ def mute_user(acct_id=str, acct=str, duration=None):
params = { params = {
"duration": duration "duration": duration
} }
success = 0
while success == 0:
try:
r = requests.post(instance_point + '/accounts' + f"/{acct_id}/mute", params, headers=headers) r = requests.post(instance_point + '/accounts' + f"/{acct_id}/mute", params, headers=headers)
r.raise_for_status() if r.status_code == 200:
logger.info(f'Пользователь {acct} был заглушен на {duration} secs') logger.info(f'Пользователь {acct} был заглушен на {duration} secs')
success = 1 else:
except: logger.error(f'Ошибка глушения {r.status_code} - {acct}')
logger.exception(f'Ошибка глушения {acct}')
time.sleep(5)
logger.info(f'Повторное глушение {acct}...')

View file

@ -62,23 +62,8 @@ def get_winner_movie(poll_status_id=str):
create_tie_breaker() create_tie_breaker()
else: else:
movie = winned_movies[0] movie = winned_movies[0]
mark_as_watched_movie(movie[1], movie[2], movie[3])
acct_suggested = movie[0]
orig_name = movie[1]
ru_name = movie[2]
year = movie[3]
win_variant = f"{orig_name} / {ru_name}, {year}"
if ru_name is None:
win_variant = f"{orig_name}, {year}"
if orig_name is None:
win_variant = f"{ru_name}, {year}"
text_winned = f'''Голосование завершилось! Победил вариант предложенный @{acct_suggested}:
{win_variant}
'''.replace('\t', '')
logger.warning("Победил " + str(movie)) logger.warning("Победил " + str(movie))
post_status(text_winned, attachments=[upload_attachment('src/FMN.png')]) mark_as_watched_movie(movie[1], movie[2], movie[3])
clear_all_states() clear_all_states()
reset_poll() reset_poll()