#!/usr/bin/env python ## Convert NCSECU CSV file to QIF. Intended to feed SECU data into GNUCash. # The SECU CSV contains split entries for debits and credits. Must convert these # to single amount entry before writing data. # Assumes SECU CSV header of Process Dates,Check Number,Description,Credit Amount,Debit Amount import csv inputfile = open('export.csv', 'rb') outputfile = open('export.qif', 'w') outputfile.write("!Type:Bank\n") class Custom(csv.excel): skipinitialspace = True csv.register_dialect('custom', Custom) reader = csv.DictReader(inputfile, dialect='custom') for row in reader: # convert SECU credit/debit amounts to single transaction amount if row['Credit Amount'] != '': amount = row['Credit Amount'] else: amount = '-'+ row['Debit Amount'] data = "D%s\nP%s\nT%s\n^\n" % (row["Process Dates"], row["Description"], amount, ) outputfile.write(data) outputfile.close()