Skip to content

Instantly share code, notes, and snippets.

@carelvwyk
Created August 23, 2017 06:53
Show Gist options
  • Save carelvwyk/aae65a93933e2e4bec57f14481ae5b7e to your computer and use it in GitHub Desktop.
Save carelvwyk/aae65a93933e2e4bec57f14481ae5b7e to your computer and use it in GitHub Desktop.
# Converts a Root.co.za CSV export of outgoing transactions
# into a format that can be imported into Google Maps
import csv
from datetime import datetime
# Parse:
with open('rootexport.csv') as data:
rdr = csv.DictReader(data)
transactions = [(
datetime.strptime(tx['Date']+tx['Time'],'%Y/%m/%d%H:%M'),
tx['Description'].replace('ZAF','').strip(),
float(tx['Amount'])
) for tx in rdr]
# Filter (Only payments larger than the R1 test payments):
transactions = [tx for tx in transactions if tx[2] < -2.0]
# Format:
formatted = [(
tx[1],
'%s - R%s' % (datetime.strftime(tx[0],'%a %d %b %H:%M'), abs(tx[2]))
) for tx in transactions]
formatted.insert(0, ('Address', 'Details'))
# Write to file for Google Maps import:
with open('maps.csv','w') as out:
writer = csv.writer(out)
writer.writerows(formatted)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment