diff --git a/Attrap_bot.py b/Attrap_bot.py index c007ce7e876380064084b048bae03a1128e22eec..d44ab10b9df42c17e78059097cbc597c7c48f9c4 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: