-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
37 lines (34 loc) · 1.68 KB
/
main.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
34
35
36
37
import pandas, sys,os
if len(sys.argv) == 1:
print("Usage: ", sys.argv[0], "INPUT_CSV_FILE")
print("Aucun fichier spécifié en argument")
exit(1)
if not os.path.isfile(sys.argv[1]):
print("Le fichier", sys.argv[1], "n'existe pas")
exit(1)
input_file = sys.argv[1]
madataframe = pandas.read_csv(input_file, encoding="utf_8_sig", delimiter=";", encoding_errors='strict')
if set(['dateOp','dateVal', 'label', 'category', 'categoryParent', 'amount', 'comment', 'accountNum', 'accountLabel', 'accountbalance']).issubset(madataframe.columns):
print("Ce fichier est valide")
else:
print("Fichier CSV invalide")
exit(1)
madataframe["payment"] = ""
madataframe.loc[madataframe["label"].str.contains("VIR"), ["payment"]] = 4
madataframe.loc[madataframe["label"].str.contains("CB"), ["payment"]] = 6
madataframe.loc[madataframe["label"].str.contains("CARTE"), ["payment"]] = 6
madataframe.loc[madataframe["label"].str.contains("PRLV SEPA"), ["payment"]] = 11
madataframe["info"] = madataframe["label"]
madataframe = madataframe.drop(columns="dateVal")
madataframe = madataframe.drop(columns="categoryParent")
madataframe = madataframe.drop(columns="accountbalance")
madataframe = madataframe.drop(columns="accountNum")
madataframe = madataframe.drop(columns="accountLabel")
madataframe = madataframe.rename(columns={"dateOp": "date"})
madataframe["memo"] = ""
madataframe["tags"] = ""
madataframe["payee"] = ""
madataframe = madataframe[["date", "payment", "info", "payee", "memo", "amount", "category", "tags"]]
output_file = input_file + "_converted.csv"
madataframe.to_csv(output_file, index=False, quoting=None, sep=";")
print("Fichier converti avec succès!")