Skip to content

Instantly share code, notes, and snippets.

@rastating
Last active December 29, 2017 13:56
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 rastating/29b0b8df4ab8ce41909d4b25adaf9d0a to your computer and use it in GitHub Desktop.
Save rastating/29b0b8df4ab8ce41909d4b25adaf9d0a to your computer and use it in GitHub Desktop.
A Python script to convert the dates in CSV exports from the Monzo mobile application into a format supported by QuickBooks Online. Requires the pandas package, which can be installed via pip.
from dateutil.parser import parse
import pandas as pd
import csv
import sys
if len(sys.argv) == 1:
print "Usage: monzo_to_qbo.py [path to Monzo csv export]"
exit(1)
RED = "\033[1;31m"
GREEN = "\033[0;32m"
def print_success(msg):
print GREEN + msg
def print_error(msg):
print RED + msg
f = open(sys.argv[1], 'rb')
reader = csv.reader(f)
headers = next(reader)
try:
date_index = headers.index('created')
except ValueError:
print_error('The "created" column could not be found in the CSV')
exit(1)
new_csv = []
new_csv.append(headers)
for row in reader:
new_row = row
value = new_row[date_index]
if value != 'created':
date = parse(value)
new_row[date_index] = date.strftime("%d-%m-%Y")
new_csv.append(new_row)
df = pd.DataFrame(new_csv)
f.close()
output_file = sys.argv[1] + '.processed.csv'
f = open(output_file, 'w')
f.write(df.to_csv(index=False, header=False))
f.close()
print_success('Saved new CSV to: ' + output_file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment