On Thu, Apr 09, 2020 at 06:20:18PM +0800, Martin Michlmayr wrote:
> CONFIG = [
>     mywrapper(ofx.Importer('1234', 'Assets:ABC')),
> ...
> 
> and then mywrapper would exactly act like any importer (i.e. it would
> just call the original importer) except that extract() would first
> call the original importer and then iterate over the entries and
> fix them up.
> 
> I'm sure this is basic Python stuff but unfortunately I can't figure
> out how to do it.  Has anyone done this and can give an example of
> such a wrapper?

Here's an untested sketch:

------------------------------------------------------------------------

class mywrapper(ofx.Importer):

    def extract(self, file, existing_entries=None):
        entries = super().extract(file, existing_entries)
        return list(map(categorize_entry, entries))

------------------------------------------------------------------------

where categorize_entry is your function that takes an input an entry and
returns an improved version of it. (Note that due to the extract
interface your function should really handle all possible Beancount
entries, not only transactions. Presumably you'll return all other
entries unchanged.)

Let me know if it works :-)

Cheers
-- 
Stefano Zacchiroli . z...@upsilon.cc . upsilon.cc/zack . . o . . . o . o
Computer Science Professor . CTO Software Heritage . . . . . o . . . o o
Former Debian Project Leader & OSI Board Director  . . . o o o . . . o .
« the first rule of tautology club is the first rule of tautology club »

-- 
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 beancount+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/beancount/20200409113514.e3dpjfdquydxaexn%40upsilon.cc.

Reply via email to