Here, expand as desired:
#!/usr/bin/env python3
"""Example processing postings using petl.
"""
from beancount import loader
from beancount.core import data
import argparse
import itertools
import petl
petl.config.look_style = "minimal"
petl.config.failonerror = True
HEADER = ["txn", "posting", "date", "account", "units", "cost"]
def rows(entries):
for txn in data.filter_txns(entries):
for posting in txn.postings:
yield (txn, posting, txn.date, posting.account, posting.units,
posting.cost)
def main():
parser = argparse.ArgumentParser(description=__doc__.strip())
parser.add_argument("filename", help="Ledger filename")
args = parser.parse_args()
entries, errors, options_map = loader.load_file(args.filename)
table = petl.wrap(itertools.chain([HEADER], rows(entries)))
print(table.cut(["date", "account", "units"]).lookallstr())
if __name__ == "__main__":
main()
On Sat, May 20, 2023 at 5:50 PM Martin Blais <[email protected]> wrote:
> There isn't one but if needed I can probably make you one in short order.
>
> On Sat, May 20, 2023 at 5:31 PM Stefano Zacchiroli <[email protected]>
> wrote:
>
>> On Sat, May 20, 2023 at 04:57:44PM -0400, Martin Blais wrote:
>> > (Note that you could build a little Python script and use petl to
>> achieve
>> > this in ~20LOC or something.)
>>
>> Is there an existing mapping from Beancount data to Petl that I'm
>> missing?
>>
>> I'm aware of Petl usage for importing data into Beancount, which makes a
>> lot of sense, because you usually have tabular data before ingesting
>> into Beancount. But I'm not aware of any bridge between Beancount
>> (presumably and more specifically: the tabular data model on which BQL
>> evaluate queries) and Petl. Would love to hear about it.
>>
>> Cheers
>> --
>> Stefano Zacchiroli . [email protected] . https://upsilon.cc/zack _. ^ ._
>> Full professor of Computer Science o o o \/|V|\/
>> Télécom Paris, Polytechnic Institute of Paris o o o </> <\>
>> Co-founder & CTO Software Heritage o o o o /\|^|/\
>> https://twitter.com/zacchiro . https://mastodon.xyz/@zacchiro '" V "'
>>
>> --
>> 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/20230520213125.q3j7mvfhks3q7pwd%40upsilon.cc
>> .
>>
>
--
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%2BhMNSw2LODCLASqo-ZZfwFfZh99wTzorw%3D9m6aRuU-iFkg%40mail.gmail.com.