Code to convert hsbc qfx files to csv in the right format for money brilliant
This commit is contained in:
16
.vscode/launch.json
vendored
Normal file
16
.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Python: Current File",
|
||||
"type": "python",
|
||||
"request": "launch",
|
||||
"program": "${file}",
|
||||
"console": "integratedTerminal",
|
||||
"justMyCode": false
|
||||
}
|
||||
]
|
||||
}
|
||||
87
Loan.qfx
Normal file
87
Loan.qfx
Normal file
@@ -0,0 +1,87 @@
|
||||
OFXHEADER:100
|
||||
DATA:OFXSGML
|
||||
VERSION:102
|
||||
SECURITY:NONE
|
||||
ENCODING:USASCII
|
||||
CHARSET:1252
|
||||
COMPRESSION:NONE
|
||||
OLDFILEUID:NONE
|
||||
NEWFILEUID:NONE
|
||||
|
||||
<OFX>
|
||||
<SIGNONMSGSRSV1>
|
||||
<SONRS>
|
||||
<STATUS>
|
||||
<CODE>0
|
||||
<SEVERITY>INFO
|
||||
</STATUS>
|
||||
<DTSERVER>20220110041351
|
||||
|
||||
<LANGUAGE>ENG
|
||||
<FI>
|
||||
<ORG>HSBC Bank Australia
|
||||
<FID>10624
|
||||
</FI>
|
||||
<INTU.BID>10624
|
||||
<INTU.USERID>XXXXXXXXXXXXXXXXXXXXXXXXXX
|
||||
</SONRS>
|
||||
</SIGNONMSGSRSV1>
|
||||
<BANKMSGSRSV1>
|
||||
<STMTTRNRS>
|
||||
<TRNUID>0
|
||||
<STATUS>
|
||||
<CODE>0
|
||||
<SEVERITY>INFO
|
||||
</STATUS>
|
||||
<STMTRS>
|
||||
<CURDEF>AUD
|
||||
<BANKACCTFROM>
|
||||
<BANKID>001610020
|
||||
<ACCTID>342101 576544258
|
||||
<ACCTTYPE>CREDITLINE
|
||||
</BANKACCTFROM>
|
||||
<BANKTRANLIST>
|
||||
<DTSTART>
|
||||
<DTEND>
|
||||
<STMTTRN>
|
||||
<TRNTYPE>CREDIT
|
||||
<DTPOSTED>20220106
|
||||
<DTUSER>20220106
|
||||
<TRNAMT>1173.71
|
||||
<FITID>202200600001
|
||||
<NAME> TRANSFER
|
||||
<MEMO>FROM 099-271041-090 AUD IB1305543 INTERNET BANKING
|
||||
</STMTTRN>
|
||||
<STMTTRN>
|
||||
<TRNTYPE>CREDIT
|
||||
<DTPOSTED>20220106
|
||||
<DTUSER>20220106
|
||||
<TRNAMT>628.81
|
||||
<FITID>202200600002
|
||||
<NAME> TRANSFER
|
||||
<MEMO>FROM 099-271041-090 AUD IB1004824 INTERNET BANKING
|
||||
</STMTTRN>
|
||||
<STMTTRN>
|
||||
<TRNTYPE>DEBIT
|
||||
<DTPOSTED>20220104
|
||||
<DTUSER>20220104
|
||||
<TRNAMT>-399440.42
|
||||
<FITID>202200400001
|
||||
<NAME> TRANSFER
|
||||
<MEMO>PEXA217198219-B2895881 LOAN DD 1592204/099-271041 DBCU00064 BANKING TERMINAL (UBT
|
||||
</STMTTRN>
|
||||
</BANKTRANLIST>
|
||||
<LEDGERBAL>
|
||||
<BALAMT>-397637.90
|
||||
<DTASOF>20220110041351
|
||||
|
||||
</LEDGERBAL>
|
||||
<AVAILBAL>
|
||||
<BALAMT>1802.52
|
||||
<DTASOF>20220110041351
|
||||
|
||||
</AVAILBAL>
|
||||
</STMTRS>
|
||||
</STMTTRNRS>
|
||||
</BANKMSGSRSV1>
|
||||
</OFX>
|
||||
4
converted_Loan.csv
Normal file
4
converted_Loan.csv
Normal file
@@ -0,0 +1,4 @@
|
||||
Date,Original Description,Category,Amount,Account Name
|
||||
06/01/2022,FROM 099-271041-090 AUD IB1305543 INTERNET BANKING,Uncategorised,1173.71,HSBC Everyday Global
|
||||
06/01/2022,FROM 099-271041-090 AUD IB1004824 INTERNET BANKING,Uncategorised,628.81,HSBC Everyday Global
|
||||
04/01/2022,PEXA217198219-B2895881 LOAN DD 1592204/099-271041 DBCU00064 BANKING TERMINAL (UBT,Uncategorised,-399440.42,HSBC Everyday Global
|
||||
|
92
converter.ipynb
Normal file
92
converter.ipynb
Normal file
@@ -0,0 +1,92 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from ofxparse import OfxParser\n",
|
||||
"import codecs"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"with codecs.open('qfx.qfx') as fileobj:\n",
|
||||
" ofx = OfxParser.parse(fileobj)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 11,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"'10624'"
|
||||
]
|
||||
},
|
||||
"execution_count": 11,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"account = ofx.account\n",
|
||||
"\n",
|
||||
"account.institution.fid"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 13,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"Decimal('9570.86')"
|
||||
]
|
||||
},
|
||||
"execution_count": 13,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"statement = account.statement\n",
|
||||
"statement.available_balance"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"interpreter": {
|
||||
"hash": "8f1f8a1d9576cf73e2f91f0cdc8e61e6f80707111d98c220b357b8bb1eb61bce"
|
||||
},
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3.8.12 64-bit ('hsbc': conda)",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.8.12"
|
||||
},
|
||||
"orig_nbformat": 4
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
50
converter.py
Normal file
50
converter.py
Normal file
@@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from csv import DictWriter
|
||||
from glob import glob
|
||||
from ofxparse import OfxParser
|
||||
|
||||
DATE_FORMAT = "%d/%m/%Y"
|
||||
|
||||
def write_csv(statement, out_file):
|
||||
print("Writing: " + out_file)
|
||||
fields = ['date', 'memo', 'category', 'amount', 'name']
|
||||
with open(out_file, 'w') as f:
|
||||
f.write("Date,Original Description,Category,Amount,Account Name")
|
||||
f.write("\r\n")
|
||||
writer = DictWriter(f, fieldnames=fields)
|
||||
for line in statement:
|
||||
writer.writerow(line)
|
||||
|
||||
|
||||
def get_statement_from_qfx(qfx):
|
||||
balance = qfx.account.statement.balance
|
||||
|
||||
statement = []
|
||||
credit_transactions = ['credit', 'dep', 'int']
|
||||
debit_transactions = ['debit', 'atm', 'pos', 'xfer', 'check']
|
||||
for transaction in qfx.account.statement.transactions:
|
||||
amount = ""
|
||||
balance = balance + transaction.amount
|
||||
|
||||
if transaction.payee.startswith("PENDING:"):
|
||||
continue
|
||||
|
||||
line = {
|
||||
'date': transaction.date.strftime(DATE_FORMAT),
|
||||
'memo' : transaction.memo,
|
||||
'category': 'Uncategorised',
|
||||
'amount': transaction.amount,
|
||||
'name': 'HSBC Everyday Global'
|
||||
}
|
||||
statement.append(line)
|
||||
return statement
|
||||
|
||||
|
||||
files = glob("*.qfx")
|
||||
for qfx_file in files:
|
||||
qfx = OfxParser.parse(open(qfx_file, encoding="latin-1"), fail_fast=False)
|
||||
statement = get_statement_from_qfx(qfx)
|
||||
out_file = "converted_" + qfx_file.replace(".qfx",".csv")
|
||||
write_csv(statement, out_file)
|
||||
Reference in New Issue
Block a user