-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvertExcelToSuperBudget.py
68 lines (63 loc) · 2.29 KB
/
convertExcelToSuperBudget.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import csv
import sys
if len(sys.argv) < 3:
print('Usage: script.py excelFile.csv outputFile.txt')
exit(1)
outputFileContents = ''
csvDelimiter = '|'
with open(sys.argv[1], newline='') as csvfile:
accountingRows = csv.reader(csvfile, delimiter=csvDelimiter)
for row in accountingRows:
currentColumn = 0
date = ''
description = ''
category = ''
value = ''
who = ''
onlyMe = ''
onlyYou = ''
for column in row:
currentColumn = currentColumn + 1
if currentColumn > 8:
print('Error: too much columns in one row!')
exit(1)
if currentColumn == 1:
dateFields = column.split('/')
date = str(int(dateFields[2]) + 2000) + '\n' + str(int(dateFields[0]) - 1) + '\n' + dateFields[1]
elif currentColumn == 2:
description = column
elif currentColumn == 3:
category = column
elif currentColumn == 4:
value = column
elif currentColumn == 5:
if column == '1':
who = 'Flo'
else:
who = 'Jess'
elif currentColumn == 6:
if column == '1' and who != 'Jess':
print('Warning: parse error. Bill attributed to both!')
print('Program will continue normally and attribute to Flo.')
elif currentColumn == 7:
if who == 'Flo':
onlyMe = column
else:
onlyYou = column
elif currentColumn == 8:
if who == 'Jess':
onlyMe = column
else:
onlyYou = column
else:
print('Error: wrong column index. Debug program.')
exit(1)
if onlyMe == '':
onlyMe = '0.0'
if onlyYou == '':
onlyYou = '0.0'
outputFileContents = outputFileContents + who + '\n' + date + '\n' + description + '\n' + category + '\n' + value + '\n' + onlyMe + '\n' + onlyYou + '\n'
with open(sys.argv[2], 'w') as outputFile:
outputFile.write(outputFileContents)
print('Successfully converted the file. Output:')
print(sys.argv[2])