From 066ef8ed9765b22bb5228844cddfa77ce1f0ae15 Mon Sep 17 00:00:00 2001 From: Bastien Le Querrec <blq@laquadrature.net> Date: Mon, 16 Dec 2024 18:40:53 +0100 Subject: [PATCH] =?UTF-8?q?Attrap=5Fbot:=20temporise=20les=20requ=C3=AAtes?= =?UTF-8?q?,=20avertit=20si=20le=20code=20de=20statut=20n'est=20pas=20200?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Attrap_bot.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Attrap_bot.py b/Attrap_bot.py index c007ce7..d44ab10 100644 --- a/Attrap_bot.py +++ b/Attrap_bot.py @@ -170,8 +170,13 @@ class Attrap_bot: send_results = False # On interroge l'API d'Attrap - response = json.loads(requests.get(request_url, timeout=(10, 120)).content) - raa = response['elements'] + api_result = requests.get(request_url, timeout=(10, 120)) + response = json.loads(api_result.content) + if api_result.status_code == 200: + raa = response['elements'] + else: + logger.warning(f'ATTENTION ! L\'API a renvoyé un code {api_result.status_code}') + raa = {} if len(raa) == 0: if os.path.isfile(status_file_path): @@ -241,6 +246,8 @@ class Attrap_bot: status = f'{last_raa_id}|{int(round(last_raa_first_seen_on.timestamp()))}' status_file.write(status) status_file.close() + # On attend quelques secondes avant de lancer la prochaine requête vers l'API + time.sleep(5) # On envoie un toot par RAA if len(raa_to_publish_mastodon) > 0: -- GitLab