Skip to content

Commit

Permalink
refait une tentative API après 1s en cas de dépassement du quota auto…
Browse files Browse the repository at this point in the history
…risé
  • Loading branch information
emillumine authored and sblondon committed May 24, 2024
1 parent 668f3d0 commit 1a871ce
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions impact/entreprises/management/commands/force_code_naf.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import time

from django.core.management.base import BaseCommand

import api.exceptions
Expand All @@ -14,13 +16,21 @@ def handle(self, *args, **options):
)
else:
try:
infos_entreprise = api.recherche_entreprises.recherche(
entreprise.siren
)
entreprise.code_NAF = infos_entreprise["code_NAF"]
entreprise.save()
maj(entreprise)
print(
f"OK: {entreprise.siren} {entreprise.denomination} {entreprise.code_NAF}"
)
except api.exceptions.TooManyRequestError as e:
time.sleep(1)
maj(entreprise)
print(
f"OK (2): {entreprise.siren} {entreprise.denomination} {entreprise.code_NAF}"
)
except api.exceptions.APIError as e:
print(f"ERREUR {e}: {entreprise.siren}")


def maj(entreprise):
infos_entreprise = api.recherche_entreprises.recherche(entreprise.siren)
entreprise.code_NAF = infos_entreprise["code_NAF"]
entreprise.save()

0 comments on commit 1a871ce

Please sign in to comment.