python script for OFX Statement Download
Christian Stimming
stimming at tuhh.de
Wed Feb 4 02:38:52 CST 2004
Derek Atkins schrieb:
> Jeremy Jongsma <jeremy at jongsma.org> writes:
>
>
>>Benoit et. al., please let me know if there's any way I can help
>>out. Unfortunately, it would have to be a way that doesn't involve C
>>coding. But I could help with feature requirements for a download
>>druid (from my user experiences with Money and Quicken), or compile a
>>list of banks and their capabilities in XML format for the druid to
>>use, or just do beta testing when the time comes...
>
>
> You might want to take a look at what HBCI does.. Also, spec'ing out
> how the UI should act in the face of direct connect _AND_
> "import-a-file" mechanisms would be a major help....
If you take the python code that connects to the bank, and then add C
functions around it that can call these routines, then you will actually
have something that is just the same as HBCI's "get transactions" action.
This HBCI action is implemented in
src/import-export/hbci/gnc-hbci-gettrans.c as follows. (This description
is for the gnucash-1-8-branch; the HEAD branch just recently switched to
the openhbci2 library, which is still not yet stable. It is almost
identical but in some points it's less intuitive than the openhbci-0.x,
so this description is still for 1-8-branch and openhbci-0.x)
- On gnucash startup, the HBCI module installs a menu item "Actions ->
Online Actions -> HBCI Get Transactions" in gncmod-hbci.c:93
- the menu item callback is defined in gnc-hbci-cb.c:57
- the actual action function gnc_hbci_gettrans() is in gnc-hbci-gettrans.c
- The account details (account id, bank code) are stored in some special
KvpFrame of the account and retrieved via gnc_hbci_get_hbci_acc()
defined in gnc-hbci-kvp.h/c, as used in gnc-hbci-gettrans.c:80
- The KvpFrame of the account also stores the timestamp of the last
transaction retrieval, which is used as a useful default for querying
the user about the time interval for transaction retrieval (a function
that is nicely implemented by the HBCI protocol) in
gnc_hbci_enter_daterange(), as used in gnc-hbci-gettrans.c:170
- The download job itself is managed by the HBCI library openhbci; you
can view its API on http://openhbci.sourceforge.net/doc/api/index.html ;
these functions would be replaced by calls to the yet-to-be-written
python/C OFX download library/code.
- The transactions are imported into gnucash by calling
gnc_gen_trans_list_add_trans() for each downloaded transaction, as
implemented in gnc_hbci_gettrans_final(); in that function, the data
structure HBCI_OutboxJobGetTransactions contains all the downloaded
transactions.
The point is this: Once someone manages to write a C function that
simply implements the action "download OFX file from the bank and return
its content" then the rest of the necessary gnucash code can be
shamelessly copied from this existing HBCI code.
I'm not sure whether a more generic framework actually makes sense. As
explained, the HBCI code already uses the "generic transaction matcher"
for the final step of the import. But all the rest of the described HBCI
code is pretty much only concerned with the step-by-step initialization
of the openhbci library and finally converting the downloaded HBCI
transaction data into gnucash transactions -- and these steps will
always be HBCI- or OFX- or whatever-specific. On the other hand, it
might yet make sense to have a common UI framework for e.g. querying the
user about the time interval for transaction retrieval
(gnc_hbci_enter_daterange() in dialog-daterange.h). If people concerned
with the OFX code decide that adding an common UI framework would help,
then I would be very open to modify the HBCI code accordingly.
Christian
More information about the gnucash-devel
mailing list