From 27b51fcd3fdd12334fdce97655c046f92bbdb591 Mon Sep 17 00:00:00 2001 From: localhost_frssoft Date: Wed, 7 Sep 2022 12:05:26 +0300 Subject: [PATCH] fedi_api will be still attempt get response --- src/fedi_api.py | 45 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/src/fedi_api.py b/src/fedi_api.py index f9a692d..4a5e902 100644 --- a/src/fedi_api.py +++ b/src/fedi_api.py @@ -18,8 +18,18 @@ def get_notifications(): "limit": 15, "types": ["mention"] } - r = requests.get(instance_point + "/notifications", json=params, headers=headers) - return r.json() + success = 0 + while success == 0: + try: + r = requests.get(instance_point + "/notifications", json=params, headers=headers) + r.raise_for_status() + success = 1 + return r.json() + except: + logger.exception('Error get notificatios') + time.sleep(30) + logger.info('Retrying get notificatios...') + def mark_as_read_notification(id_notification): @@ -33,7 +43,7 @@ def mark_as_read_notification(id_notification): except: logger.exception(f'Error read notification {id_notification}') time.sleep(30) - logger.info('Retrying read notification {id_notification}...') + logger.info(f'Retrying read notification {id_notification}...') def get_status_context(status_id): @@ -51,8 +61,18 @@ def get_status_context(status_id): def get_status(status_id): - r = requests.get(instance_point + f"/statuses/{status_id}", headers=headers) - return r.json() + success = 0 + while success == 0: + try: + r = requests.get(instance_point + f"/statuses/{status_id}", headers=headers) + r.raise_for_status() + success = 1 + return r.json() + except: + logger.exception(f'Error get status {status_id}') + time.sleep(30) + logger.info(f'Retrying get status {status_id}') + def post_status(text, reply_to_status_id=None, poll_options=None, poll_expires=345600, attachments=None): @@ -92,8 +112,19 @@ def upload_attachment(file_path): 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'] + success = 0 + while success == 0: + try: + r = requests.post(instance_point + "/media", params, files=file, headers=headers) + r.raise_for_status() + success = 1 + return r.json()['id'] + except: + logger.exception(f'Error uploading {file_path} attachment') + time.sleep(5) + logger.info(f'Retrying upload {file_path}...') + + def mute_user(acct_id=str, acct=str, duration=None):