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.
Is there a simple way to do this?
Thanks
M.