Thank you Patrick and Zack for your patience and explanations!
I got both approches working.
Zack's approach seems simpler to me, but the problem is that it's a
sub-class of ofx.Importer whereas I was hoping for a wrapper that
I could apply to any importer. In the case I'm trying to solve,
I only have OFX so I might go with this approach.
Patrick's hook mechanism is more flexible in that regard since
I can apply it to any importer and I could even apply different
hooks to different importers. The downside is that it relies
on smart_importer which has a lot of ML dependencies.
Patrick, have you (or other smart_importer developers) proposed that
hook mechanism for inclusion into beancount?
For those equally Python challenged as me, here's some example code:
Note: both attach the meta-data to non-txn transactions (like
'balance'). There needs to be a check for transactions.
1) Using Zack's sub-class approach:
def categorize_entry(entry):
entry.meta['test'] = 'foo'
return entry
class myOFX(ofx.Importer):
def extract(self, file, existing_entries=None):
entries = super().extract(file, existing_entries)
return list(map(categorize_entry, entries))
CONFIG = [
myOFX('1...', 'Assets:...'),
]
2) Using smart-import's hook mechanism:
from smart_importer.hooks import apply_hooks, ImporterHook
class SPIImporter(ImporterHook):
def __call__(self, importer, file, imported_entries, existing_entries):
self.account = importer.file_account(file)
for entry in imported_entries:
entry.meta['test'] = 'foo'
return imported_entries
CONFIG = [
apply_hooks(ofx.Importer('1...', 'Assets:...'), [SPIImporter()]),
]
--
Martin Michlmayr
https://www.cyrius.com/
--
You received this message because you are subscribed to the Google Groups
"Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/beancount/20200410041455.GK21554%40jirafa.cyrius.com.