diff --git a/lemarche/networks/management/commands/link_siae_to_network.py b/lemarche/networks/management/commands/link_siae_to_network.py index 4d897dcab..bbeaef9bd 100644 --- a/lemarche/networks/management/commands/link_siae_to_network.py +++ b/lemarche/networks/management/commands/link_siae_to_network.py @@ -8,6 +8,7 @@ class Command(BaseCommand): """ poetry run python manage.py link_siae_to_network --file file.csv --network 8 --siret-column 'SIRET' --dry-run + poetry run python manage.py link_siae_to_network --file file.csv --network 8 --siret-column 'SIRET' """ def add_arguments(self, parser): @@ -19,14 +20,12 @@ def add_arguments(self, parser): def handle(self, *args, **options): siae_list = list() network = Network.objects.get(id=options["network"]) - # header = list() self.stdout_info("-" * 80) self.stdout_info("Reading file...") with open(options["file"]) as csv_file: csvreader = csv.DictReader(csv_file, delimiter=",") - # header = csvreader.fieldnames for index, row in enumerate(csvreader): row["index"] = index + 2 siae_list.append(row) @@ -39,25 +38,19 @@ def handle(self, *args, **options): siae_network_added = 0 for index, s in enumerate(siae_list): - print("====================") - # print(index) - # print(s[options["siret_column"]]) siae = None try: siae = Siae.objects.get(siret=s[options["siret_column"]]) if network in siae.networks.all(): - # print("Siae Network already linked") - siae_list[index]["Déjà ajouté"] = "Oui" + # Siae Network already linked siae_has_network += 1 else: - # print("Siae Network new links") - siae_list[index]["Ajouté"] = "Oui" + # Siae Network new link siae_network_added += 1 if not options["dry_run"]: siae.networks.add(network) except: # noqa - # print("Siae missing", s[options["siret_column"]]) - siae_list[index]["SIRET manquant"] = "Oui" + # Siae missing siae_missing += 1 print("====================") @@ -65,10 +58,3 @@ def handle(self, *args, **options): print("Siae missing", siae_missing) print("Siae Network already linked", siae_has_network) print("Siae Network new links", siae_network_added) - - # with open(f"{file_path}-enriched.csv", "w") as csv_file: - # fieldnames = ["index"] + header + ["SIRET manquant", "Inscrite", "Déjà ajouté", "Ajouté"] - # writer = csv.DictWriter(csv_file, fieldnames=fieldnames) - # writer.writeheader() - # for s in fei_siae_list: - # writer.writerow(s)