-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_inflow_transactions.py
executable file
·36 lines (29 loc) · 1.1 KB
/
get_inflow_transactions.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
#! /usr/bin/python
import argparse
import re
def main(csv_file, threshold=None):
with open(csv_file, 'r') as handle:
lines = handle.read().splitlines()
columns = lines[0].split(',')
amount_column = columns.index('"Inflow"')
payee_column = columns.index('"Payee"')
payees_to_skip = ['Transfer : GST', 'Transfer : ANZ Credit', 'Transfer : ANZ Checking', 'Weta Digital']
for i, line in enumerate(lines[1:]):
try:
split = eval(line.replace('$', ''))
amount = float(split[amount_column])
if not amount or (threshold and amount < threshold):
continue
payee = split[payee_column]
if payee in payees_to_skip:
continue
print '%04d %s' % (i, line)
except:
print 'error on line %s: %s' % (i+1, line)
raise
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('csv_file')
parser.add_argument('--threshold', type=float, default=None)
args = parser.parse_args()
main(args.csv_file, threshold=args.threshold)