diff --git a/src/FMN.png b/src/FMN.png new file mode 100644 index 0000000..426979b Binary files /dev/null and b/src/FMN.png differ diff --git a/src/fedi_api.py b/src/fedi_api.py index 5c0ee1a..afd179a 100644 --- a/src/fedi_api.py +++ b/src/fedi_api.py @@ -35,7 +35,7 @@ def get_status(status_id): return r.json() -def post_status(text, reply_to_status_id=None, poll_options=None, poll_expires=345600): +def post_status(text, reply_to_status_id=None, poll_options=None, poll_expires=345600, attachments=None): poll = None if poll_options is not None: poll = { @@ -43,14 +43,28 @@ def post_status(text, reply_to_status_id=None, poll_options=None, poll_expires=3 "expires_in": poll_expires, "multiple": True } - print(poll_options) params = { "status": text, "in_reply_to_id": reply_to_status_id, "visibility": "unlisted", "content_type": "text/plain", + "language": "ru", "poll": poll } + if attachments: + params['media_ids'] = attachments r = requests.post(instance_point + "/statuses", json=params, headers=headers) return r.json() + +def upload_attachment(file_path): + file = { + "file": open(file_path, mode='rb') + } + params = { + "description": "Fediverse Movie Night\nВоскресенье, 21:00\nLIVE ON XXIV Production", + } + r = requests.post(instance_point + "/media", params, files=file, headers=headers) + return r.json()['id'] + + diff --git a/src/fmn_poll.py b/src/fmn_poll.py index 646f239..0ecec38 100644 --- a/src/fmn_poll.py +++ b/src/fmn_poll.py @@ -1,4 +1,4 @@ -from src.fedi_api import get_status, post_status +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 collections import Counter @@ -27,11 +27,11 @@ def create_poll_movies(text=text_create_poll, poll_expires=345600): if orig_name is None: poll_option_string = f"{ru_name}, {year} ({acct})" formated_poll_options.append(poll_option_string) - - poll_status_id = post_status(text, None, formated_poll_options, poll_expires=poll_expires)['id'] + poll_status_id = post_status(text, None, formated_poll_options, + poll_expires=poll_expires, attachments=[upload_attachment('src/FMN.png')]) logger.info('Голосовалка создана') add_state('poll_expires_at', int(time.time()) + poll_expires) - add_state('poll_status_id', poll_status_id) + add_state('poll_status_id', poll_status_id['id']) return poll_status_id @@ -75,5 +75,5 @@ def create_tie_breaker(count_tie=1): poll_expires = 8*60*60 else: poll_expires = 4*60*60 - tie_poll = create_poll_movies("[Чисто проверить как отрабатывают тай брекеры и в целом препарирование опросов] TIE BREAKER!!!", poll_expires) + tie_poll = create_poll_movies("TIE BREAKER!!!\n\nВыбираем из победителей!", poll_expires) diff --git a/src/listener_mention.py b/src/listener_mention.py index 128a664..8e8d237 100644 --- a/src/listener_mention.py +++ b/src/listener_mention.py @@ -1,4 +1,4 @@ -from src.fedi_api import get_notifications, mark_as_read_notification, post_status +from src.fedi_api import get_notifications, mark_as_read_notification, post_status, upload_attachment from src.fmn_states_db import add_state from config import main_admin_bot, limit_movies_per_user, limit_all_movies_poll, hour_poll_posting @@ -25,7 +25,7 @@ def get_control_mention(acct_admin_bot=str): movies_accept_time = stop_thread_scan.strftime('%H:%M %d.%m.%Y MSK') stop_thread_scan = time.mktime(time.struct_time(stop_thread_scan.timetuple())) - post_status(start_collect_movies_text(movies_accept_time, next_movie_watching), st_id) + post_status(start_collect_movies_text(movies_accept_time, next_movie_watching), st_id, attachments=[upload_attachment('src/FMN.png')]) time.sleep(0.2) mark_as_read_notification(i['id']) add_state('stop_thread_scan', int(stop_thread_scan))