1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| # coding: utf-8
import csv
import glob
import re
for filename in glob.glob('*.csv'):
with open(filename, newline='') as monFichierEntre:
reader = csv.reader(monFichierEntre, delimiter=';', doublequote=False)
nom_sortie='sortie_'+filename
with open(nom_sortie,'w',newline='') as monFichierSortie:
writer = csv.writer(monFichierSortie, delimiter=';', quoting=csv.QUOTE_NONE, escapechar='', quotechar='')
for row in reader:
# On ne garde que le format bouteille
if row[4]=='75':
formatb='BO'
# Nom du chateau
chateau=row[2]+' '+row[3]
chateau=chateau.replace('é','e')
chateau=chateau.replace('è','e')
chateau=chateau.replace('â','a')
chateau=chateau.replace('É','E')
chateau=chateau.replace('"','')
chateau=chateau.replace(',','')
chateau=chateau.replace('.','')
#chateau=re.sub(r'[0-9]','',chateau)
# année
if row[0]=='0':
annee='2014'
else:
annee=row[0]
# Prix
prix=row[7]
# quantite
quantite='0'
# conditionnement
conditionnement='CBO12'
# commentaires (on met la quantité et les commentaires)
commentaires='QTE : '+row[5]
# tarif officieux
officieux='1'
else :
chateau=''
annee=''
formatb=''
prix=''
conditionnement=''
quantite=''
commentaires=''
officieux=''
# On fabrique la nouvelle ligne dans l'ordre voulu
trou=''
newRow=[chateau,annee,formatb,prix,quantite,conditionnement,commentaires,officieux,trou,trou]
writer.writerow(newRow)
monFichierEntre.close() |