-
Notifications
You must be signed in to change notification settings - Fork 0
/
recherche_csv.py
33 lines (30 loc) · 1.28 KB
/
recherche_csv.py
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
import glob
import csv
import os
import sys
def recherche_csv(value_desired, type_tache):
try :
#on essate de recuperer le fichier texte le plus recent
pathname = os.path.dirname(sys.argv[0])
newest_f = max(glob.iglob(pathname + r'\Tache_associee\*.[c][s][v]'), key=os.path.getctime)
i = 0
#on lis le fichier
with open(newest_f, "rt") as originFile:
try:
for row in csv.reader(originFile, delimiter=';', quoting=csv.QUOTE_NONE):
if (str('[')+str(value_desired)+str(']')) in str(row[0]):
i = i + 1
#travail si la tache est une boite
if type_tache == 'boite':
return row[0]
else :
if (str(value_desired)) in str(row[0]):
i = i + 1
#travail si la tache est une boite
if type_tache == 'boite':
return row[0]
except csv.Error as e:
print('file {}, row {}: {}'.format(newest_f, str(i), e))
originFile.close()
except Exception as e:
print(e)