mirror of
https://git.phreedom.club/localhost_frssoft/FMN_bot.git
synced 2024-11-24 22:40:57 +01:00
Added some exceptions handlers in fedi api
This commit is contained in:
parent
f3ef0e4531
commit
f142d5451f
|
@ -25,25 +25,31 @@ def get_notifications():
|
||||||
|
|
||||||
|
|
||||||
def mark_as_read_notification(id_notification):
|
def mark_as_read_notification(id_notification):
|
||||||
r = requests.post(instance_point + f"/notifications/{id_notification}/dismiss", headers=headers)
|
success = 0
|
||||||
return r.json()
|
while success == 0:
|
||||||
|
try:
|
||||||
|
r = requests.post(instance_point + f"/notifications/{id_notification}/dismiss", headers=headers)
|
||||||
|
r.raise_for_status()
|
||||||
|
success = 1
|
||||||
|
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):
|
||||||
r = requests.get(instance_point + f"/statuses/{status_id}/context", headers=headers)
|
success = 0
|
||||||
if r.status_code == 200:
|
while success == 0:
|
||||||
return r.json()
|
try:
|
||||||
else:
|
r = requests.get(instance_point + f"/statuses/{status_id}/context", headers=headers)
|
||||||
http_code = r.status_code
|
r.raise_for_status()
|
||||||
logger.error(f'Ошибка получения контекста треда {status_id}: {http_code}')
|
success = 1
|
||||||
logger.error(str(r.headers))
|
return r.json()
|
||||||
while r.status_code != 200:
|
except:
|
||||||
|
logger.exception(f'Ошибка получения контекста треда {status_id}')
|
||||||
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):
|
||||||
|
@ -69,8 +75,16 @@ 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
|
||||||
r = requests.post(instance_point + "/statuses", json=params, headers=headers)
|
success = 0
|
||||||
return r.json()
|
while success == 0:
|
||||||
|
try:
|
||||||
|
r = requests.post(instance_point + "/statuses", json=params, headers=headers)
|
||||||
|
r.raise_for_status()
|
||||||
|
success = 1
|
||||||
|
return r.json()
|
||||||
|
except:
|
||||||
|
logger.exception('Error send status, retrying...')
|
||||||
|
time.sleep(5)
|
||||||
|
|
||||||
|
|
||||||
def upload_attachment(file_path):
|
def upload_attachment(file_path):
|
||||||
|
@ -88,9 +102,15 @@ def mute_user(acct_id=str, acct=str, duration=None):
|
||||||
params = {
|
params = {
|
||||||
"duration": duration
|
"duration": duration
|
||||||
}
|
}
|
||||||
r = requests.post(instance_point + '/accounts' + f"/{acct_id}/mute", params, headers=headers)
|
success = 0
|
||||||
if r.status_code == 200:
|
while success == 0:
|
||||||
logger.info(f'Пользователь {acct} был заглушен на {duration} secs')
|
try:
|
||||||
else:
|
r = requests.post(instance_point + '/accounts' + f"/{acct_id}/mute", params, headers=headers)
|
||||||
logger.error(f'Ошибка глушения {r.status_code} - {acct}')
|
r.raise_for_status()
|
||||||
|
logger.info(f'Пользователь {acct} был заглушен на {duration} secs')
|
||||||
|
success = 1
|
||||||
|
except:
|
||||||
|
logger.exception(f'Ошибка глушения {acct}')
|
||||||
|
time.sleep(5)
|
||||||
|
logger.info(f'Повторное глушение {acct}...')
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user