Created
July 24, 2022 10:37
-
-
Save cquest/614b8f44cda1ff723f2beff6242cdbc1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/python3 | |
""" | |
Script de remise en forme du fichier des copropriétés | |
Auteur: Christian Quest - 24-08-2022 | |
Licence: WTFPL | |
""" | |
import sys, csv, re | |
re_adr = re.compile(r'(.*)([0-9]{5}) (.*)') | |
# NEXITY LAMY( syndic professionnel) SIRET 48753009902584, PARIS 8 Exerce un mandat de syndic | |
re_syndic = re.compile(r'(.*)\( syndic (.*)\) SIRET ([0-9]{14}|null), (.*) (Exerce.*)') | |
out = csv.writer(open('copro.csv','w')) | |
with open(sys.argv[1],'r') as copro: | |
reader = csv.reader(copro, delimiter=';') | |
for data in reader: | |
if data[0] == 'num_immat': | |
data.append('code_postal') | |
data.append('ville') | |
data.append('type_syndic') | |
data.append('siret_syndic') | |
data.append('ville_syndic') | |
data.append('exercice_syndic') | |
else: | |
match = re.search(re_adr, data[1]) | |
if match: | |
data[1] = match.group(1) | |
data.append(match.group(2)) | |
data.append(match.group(3)) | |
else: | |
data.append('') | |
data.append('') | |
if data[1] != '': | |
print(data[1]) | |
match = re.search(re_syndic, data[2]) | |
if match: | |
data[2] = match.group(1) | |
data.append(match.group(2)) | |
if match.group(3) == 'null': | |
data.append('') | |
else: | |
data.append(match.group(3)) | |
data.append(match.group(4)) | |
data.append(match.group(5)) | |
else: | |
data.append('') | |
data.append('') | |
data.append('') | |
data.append('') | |
print(data[2]) | |
out.writerow(data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment