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
|
#!/usr/bin/env python
"""
script must:
- remove all 0.00 amounts
- keep 0.00 amounts-in when Payee == "Starting Balance"
"""
import re
import argparse
# remove zeros and escaped quotes
zeros = re.compile(',0[.]00,')
escaped_quotes = re.compile('\"Last Temptation\"')
def scrub(s):
if "Last Temptation" in s:
s = escaped_quotes.sub('', s)
elif "Starting Balance" in s:
s = zeros.sub(',,', s, count=1)
else:
s = zeros.sub(',,', s)
return s
parser = argparse.ArgumentParser()
parser.add_argument(
'input', metavar='INPUT', type=str,
help='The input csv file, exported from YNAB'
)
parser.add_argument(
'output', metavar='OUTPUT', type=str,
help='The output csv file.'
)
if __name__ == '__main__':
args = parser.parse_args()
with open(args.input, 'r') as f:
csv = f.readlines()
scrubbed = [scrub(line) for line in csv[1:]]
with open(args.output, 'w') as f:
for line in scrubbed:
f.write(line)
|