-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvertSuperBudgetToExcel.py
81 lines (75 loc) · 2.44 KB
/
convertSuperBudgetToExcel.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
69
70
71
72
73
74
75
76
77
78
79
80
81
import csv
import sys
if len(sys.argv) < 3:
print('Usage: script.py superBudgetFile.txt outputFile.csv')
exit(1)
outputFileContents = ''
delimiter = '|'
with open(sys.argv[1], newline='') as superBudgetFile:
currentRow = 0
year = ''
month = ''
day = ''
description = ''
category = ''
value = ''
isFlo = ''
isJess = ''
onlyFlo = ''
onlyJess = ''
for row in superBudgetFile:
currentRow = currentRow + 1
row = row.replace('\n', '')
row = row.replace('\r', '')
if currentRow > 9:
currentRow = 1
if currentRow == 1:
if row == 'Flo':
isFlo = '1'
isJess = ''
else:
isFlo = ''
isJess = '1'
elif currentRow == 2:
year = str(int(row) - 2000)
elif currentRow == 3:
month = str(int(row) + 1)
elif currentRow == 4:
day = row
elif currentRow == 5:
description = row
elif currentRow == 6:
category = row
elif currentRow == 7:
value = row
elif currentRow == 8:
if isFlo == '1':
onlyFlo = row
else:
onlyJess = row
elif currentRow == 9:
if isFlo == '1':
onlyJess = row
else:
onlyFlo = row
else:
print('Error: wrong column index. Debug program.')
exit(1)
if currentRow == 9:
if onlyFlo == '0.0':
onlyFlo = ''
if onlyJess == '0.0':
onlyJess = ''
outputFileContents = outputFileContents + month + '/' + day + '/' + year + delimiter
outputFileContents = outputFileContents + description + delimiter
outputFileContents = outputFileContents + category + delimiter
outputFileContents = outputFileContents + value + delimiter
outputFileContents = outputFileContents + isFlo + delimiter
outputFileContents = outputFileContents + isJess + delimiter
outputFileContents = outputFileContents + onlyFlo + delimiter
outputFileContents = outputFileContents + onlyJess
outputFileContents = outputFileContents + '\n'
with open(sys.argv[2], 'w') as outputFile:
outputFile.write(outputFileContents)
print('Successfully converted the file. Output:')
print(sys.argv[2])