Created
September 13, 2011 13:33
-
-
Save nicholas-gh/1213809 to your computer and use it in GitHub Desktop.
Receipt Bank to QIF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
## Convert from https://www.receipt-bank.com CSV format to QIF | |
# ./receipt-bank-to-qif.py <receipts.csv >receipts.qif | |
import csv, sys | |
rows = csv.DictReader(sys.stdin) | |
# read it all in, then we'll write out one payment method at a time | |
data = {} | |
for row in rows: | |
data.setdefault(row['Payment Method'],[]).append(row) | |
print """\ | |
!Type:Cat | |
!Option:AutoSwitch""" | |
# give the list of accounts/payment methods that are going to come up later | |
for payment in data.keys(): | |
print "!Account" | |
print "N%s" % payment | |
print "^" | |
print """\ | |
!Clear:AutoSwitch | |
""" | |
for payment, transactions in data.items(): | |
if payment == "cash": | |
typ = "Cash" | |
else: | |
# could be CCard too? | |
typ = "Bank" | |
print """\ | |
!Account | |
N%s | |
^ | |
!Type:%s | |
""" % (payment, typ) | |
for transaction in transactions: | |
if payment == 'cash': | |
transaction['cleared'] = 'c' | |
else: | |
transaction['cleared'] = '' | |
print """\ | |
D%(Date)s | |
T-%(Total)s | |
M%(Note)s | |
P%(Payee)s | |
N%(Receipt ID)s | |
C%(cleared)s | |
L%(Category)s | |
^""" % transaction | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment