Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed Mar 7, 2024
1 parent e560da6 commit 0438f4f
Showing 1 changed file with 3 additions and 18 deletions.
21 changes: 3 additions & 18 deletions lemarche/networks/management/commands/link_siae_to_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,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)
Expand All @@ -39,36 +37,23 @@ 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("====================")
print("Total", len(siae_list))
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)

0 comments on commit 0438f4f

Please sign in to comment.