Skip to content

Instantly share code, notes, and snippets.

@jcdk
Created February 11, 2023 00:24
Show Gist options
  • Save jcdk/6f1cadc245822c4ab32afec4bfb1ff2b to your computer and use it in GitHub Desktop.
Save jcdk/6f1cadc245822c4ab32afec4bfb1ff2b to your computer and use it in GitHub Desktop.
WePay CSV to QFX conversion script in python. Just change the filenames and run the script in the same folder as your input csv. With some modification, this script will allow you to prep a QFX file for MoneyMinder import from a payment processor like WePay that doesn't provide QFX files.
import csv
from datetime import datetime
# Open the CSV file
with open('wepay-input.csv', 'r') as csvfile:
# Create a reader object
reader = csv.DictReader(csvfile)
# Open the QFX file
with open('wepay-output.qfx', 'w') as qfxfile:
# Write the header for the QFX file
qfxfile.write('OFXHEADER:100\nDATA:OFXSGML\nVERSION:102\nSECURITY:NONE\nENCODING:USASCII\nCHARSET:1252\nCOMPRESSION:NONE\nOLDFILEUID:NONE\nNEWFILEUID:NONE\n\n<OFX>\n<BANKMSGSRSV1>\n<STMTTRNRS>\n<STMTRS>\n<BANKTRANLIST>\n')
# Iterate through the rows in the CSV file
for row in reader:
# Write the data for each transaction to the QFX file
datetime_str = row['date']
# datetime_object = datetime.strptime(datetime_str, '%m/%d/%y %H:%M')
datetime_object = datetime.strptime(datetime_str, '%Y-%m-%d %H:%M:%S %Z')
# date object to string with format %Y%m%d%H%M%S[%z:%Z]
dateFmt = datetime_object.strftime('%Y%m%d%H%M%S')+'[0:GMT]'
# OFX transaction type:
if row['payee'] == 'Chase':
txType = 'TRANSFER'
elif row['type'] == 'Payment':
txType = 'CREDIT'
else:
txType = 'DEBIT'
# skip transfers in output file for now
if txType != 'TRANSFER':
qfxfile.write(f'<STMTTRN>\n<DTPOSTED>{dateFmt}</DTPOSTED>\n<TRNTYPE>{txType}<TRNTYPE>\n<FITID>{row["transaction_id"]}</FITID>\n<NAME>{row["payer"]}</NAME>\n<MEMO>gross:{row["amount"]} fees:{row["fees"]} {row["status"]} {row["transaction_id"]}</MEMO>\n<TRNAMT>{row["net"]}</TRNAMT>\n<REFNUM>{row["payer"]}</REFNUM>\n</STMTTRN>\n')
# Write the footer for the QFX file
qfxfile.write('</BANKTRANLIST>\n</STMTRS>\n</STMTTRNRS>\n</BANKMSGSRSV1>\n</OFX>')
# convert row['date'] to python date object and format it as %Y%m%d%H%M%S[%z:%Z]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment