On Thu, Apr 09, 2020 at 10:15:23AM +0800, Martin Michlmayr wrote: > The "Importing External Data in Beancount" document says: > > "Beancount does not currently provide a mechanism to automatically > categorize transactions. You can build this into your importer code. I > want to provide a hook for the user to register a completion function > that could run across all the importers where you could hook that code > in." [...] > What would be an elegant way to wrap the importers into code that > can run over the entries and improve the transactions?
For I'm using only a custom CSV importer, which inherits from the built-in CSV importer, and the only thing I'm doing is categorizing transactions, i.e., determining the account of one leg of the transaction. To that end, I'm reusing the notion of "categorizer" supported by the built-in CSV importer. It's a function from and to entries; so even if I'm using it only for changing the account, you could in theory change whatever you want of the extracted entries. But I understand you're not using the CSV importer, so the categorizer abstraction is probably not what you're looking for. Still, the importer.py protocol, which you've probably implemented, has this: extract(): Extract directives from a file's contents and return of list of entries. which: Returns: A list of new, imported directives (usually mostly Transactions) extracted from the file. So, assuming you already have an importer that returns "raw" transactions, you can just have a function that improves your transactions and map it onto the output of extract(), I believe. It can also be a wrapper class around any importer that turns a "dumb" importer into a "smart" one, that enriches transactions as you please. Is that what you're looking for here? 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/20200409091305.pzq43psennr4eshb%40upsilon.cc.