I would just write a loop against the API. shorter and more powerful.;
On Thu, Apr 15, 2021 at 12:32 PM Daniele Nicolodi <dani...@grinta.net> wrote: > On 15/04/2021 15:31, Daniele Nicolodi wrote: > > Hello, > > > > I am writing a tool that should operate on a selection of entries from a > > Benacount ledger. I could come up with my own little DSL to do the > > selection, but we already have BQL, thus I think reusing it would be > nice. > > Replying to myself. There is not a ready made function, but it is easy > to put together one. For example: > > from beancount.query import query_compile > from beancount.query import query_env > from beancount.query import query_execute > from beancount.query import query_parser > > > def filter_entries(entries, options, what): > env_targets = query_env.TargetsEnvironment() > env_entries = query_env.FilterEntriesEnvironment() > env_postings = query_env.FilterPostingsEnvironment() > > # Parse the BQL statement. > parser = query_parser.Parser() > statement = parser.parse(f'PRINT FROM {what:}') > > # Compile the BQL statement. > compiled = query_compile.compile(statement, > env_targets, env_postings, env_entries) > > # Execute only the filtering part of the BQL statement. > context = query_execute.create_row_context(entries, options) > entries = query_execute.filter_entries(compiled.c_from, > entries, options, context) > > return entries > > Cheers, > Dan > > -- > 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/74e9e559-14e0-3065-63e5-171af236cf09%40grinta.net > . > -- 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/CAK21%2BhP3uR6-%3DptqH1NgS2h1Qgwd4Yvu1hA7M%3Dobq1RtehsOmw%40mail.gmail.com.