Skip to content

Commit

Permalink
extract api call to function
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed Nov 27, 2023
1 parent 45ed29e commit 6de6be3
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions lemarche/siaes/management/commands/sync_c1_c4.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,25 @@
C1_EXTRA_KEYS = ["convention_is_active", "convention_asp_id"]


def get_siae_list_from_api_emplois_inclusion():
siae_list = list()
pagination = 0

# loop on API to fetch all the data
while True:
response = requests.get(f"{API_ENDPOINT}?page_size={pagination}", headers=API_HEADERS)
data = response.json()
if data["results"]:
for siae in response.json()["results"]:
siae_list.append(siae)
if data["next"]:
pagination += 1000
else:
break

return siae_list


def map_siae_presta_type(siae_kind):
if siae_kind:
if siae_kind in ["ETTI", "AI"]:
Expand Down Expand Up @@ -154,22 +173,9 @@ def handle(self, dry_run=False, **options):
self.stdout_messages_success(msg_success)
api_slack.send_message_to_channel("\n".join(msg_success))

def c1_export(self):
def c1_export(self): # noqa C901
try:
c1_list_temp = list()
pagination = 0

# loop on API to fetch all the data
while True:
response = requests.get(f"{API_ENDPOINT}?page_size={pagination}", headers=API_HEADERS)
data = response.json()
if data["results"]:
for siae in response.json()["results"]:
c1_list_temp.append(siae)
if data["next"]:
pagination += 1000
else:
break
c1_list_temp = get_siae_list_from_api_emplois_inclusion()

# clean fields
c1_list_cleaned = list()
Expand Down

0 comments on commit 6de6be3

Please sign in to comment.