On Fri, Oct 11, 2019 at 5:06 PM <[email protected]> wrote:
>
> I've been playing with Beancount API for some custom interactive importers, 
> and so far it is doing everything I want, except (perhaps) for one thing.
>
> I would like to make a `merge` that takes the new entries generated by the 
> import and inserts them in the main file (let's assume only one file for 
> now), in the right location ordering them by date.
>
> So I did the obvious round-trip (for the time being to a new file):
>
>     existing, err, opts = load_file(main)
>     if err:
>         raise Exception("The main file contains errors. Aborting")
>     new, _, _ = load_file(filename)
>     existing.extend(new)
>
>     res = sorted(existing, key=lambda c: c.date)
>
>     with open(f"{main}_new", "w") as f:
>         print_entries(res, file=f)
>
> But this way comments, tags, options (perhaps more) are not preserved.

Yes, that won't work. What it'll output is the processed stream of
transactions, not the ones it parsed.
(There are two stages: parsing, then running the plugins makes a bunch
of changes to the stream.)


>
> Is there a simple way to do this?

I would do this differently; the lo-fi version is to insert a comment
with a unique marker and have your script insert the new transactions
right before it.
You'll have to sort them out based on your rules.




> Thanks
>
> M.
>
> --
> 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/fe38849b-79e5-4055-b77e-d5ba6f3cd920%40googlegroups.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/CAK21%2BhOWmo_oNkPKrJFqijd-wEH0J79AvXQZ1RWXrp8Nh6CMRQ%40mail.gmail.com.

Reply via email to