summaryrefslogtreecommitdiff
path: root/preprocess-ynab-export
diff options
context:
space:
mode:
authorBen Sima <ben@bsima.me>2018-06-13 21:36:56 -0700
committerBen Sima <ben@bsima.me>2018-06-13 21:36:56 -0700
commit77c9a177b2b595d4ce25095b58e2388fe33cc97a (patch)
tree0853d5c92d67538760005b9c4635a90115bd7ba4 /preprocess-ynab-export
init
Diffstat (limited to 'preprocess-ynab-export')
-rwxr-xr-xpreprocess-ynab-export51
1 files changed, 51 insertions, 0 deletions
diff --git a/preprocess-ynab-export b/preprocess-ynab-export
new file mode 100755
index 0000000..e0f0b7d
--- /dev/null
+++ b/preprocess-ynab-export
@@ -0,0 +1,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)
+
+
+