Skip to content

Instantly share code, notes, and snippets.

@ArrEssJay
Last active May 17, 2018 23:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ArrEssJay/6af9f13aec4c89ee7cdfcad083184e83 to your computer and use it in GitHub Desktop.
Save ArrEssJay/6af9f13aec4c89ee7cdfcad083184e83 to your computer and use it in GitHub Desktop.
Cleanup MEBank (AU) transaction export CSV files.
#!/usr/local/bin/python3
import csv
import argparse
import sys
parser = argparse.ArgumentParser(description='Cleanup MEbank (AU) CSV files with descriptions split over multiple lines')
parser.add_argument('infile', nargs='?', type=argparse.FileType('r'), default=sys.stdin)
parser.add_argument('outfile', nargs='?', type=argparse.FileType('w'), default=sys.stdout)
parser.add_argument('--invertorder', action='store_true')
args = parser.parse_args()
reader = csv.reader(args.infile, delimiter=',', skipinitialspace=True)
writer = csv.writer(args.outfile, delimiter=',')
descriptions = []
transactions = []
for row in reader:
descriptions.insert(0, row[1])
if row[2] == '':
pass
else:
#remove whitespace/currency/formatting
row[2] = row[2].replace(" ","")
row[2] = row[2].replace("$","")
row[2] = row[2].replace(",","")
row[3] = row[3].replace(",","")
row[3] = row[3].replace("$","")
description = ','.join(descriptions)
descriptions = []
transactions.append([row[0],description,row[2],row[3]])
if args.invertorder:
#reverse order except for first line with column headings
transactions_=transactions[::-1]
transactions_.insert(0,transactions[0])
del transactions_[-1]
transactions=transactions_
for row in transactions:
writer.writerow(row)
@ArrEssJay
Copy link
Author

MEBank export transactions with some 'interesting' formatting, including splitting transaction descriptions over multiple lines. Most financial software expects one transaction per line. This script just combines these lines and sanitises the values, removing any formatting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment