RSS Amplifier

Rida Ayed · Jul 14, 2021

Parse ledger-cli using python

0
Sign in to vote or save

This page cannot be shown here. You can still read it on the original site — the toolbar below keeps your place in the directory.

#Content of file.dat 2099/02/07 * foo ; MD5Sum: 4d2965fa2879f3c528006f2e9c3bca8d Expenses:Groceries CHF 10 Assets:Cash 2099/11/07 * bar ; MD5Sum: 4d2965fa2879f3c528006f2e9c3bca8e Expenses:Groceries CHF 20 Assets:Cash import subprocess from datetime import datetime format = "'%(cleared) \t %D \t %P \t %(quantity(scrub(display_amount))) \t %(join(note | xact.note)) \n '" query = "ledger -f file.dat…

#Content of file.dat
2099/02/07 * foo
    ; MD5Sum: 4d2965fa2879f3c528006f2e9c3bca8d
    Expenses:Groceries                                 CHF 10
    Assets:Cash
2099/11/07 * bar
    ; MD5Sum: 4d2965fa2879f3c528006f2e9c3bca8e
    Expenses:Groceries                                 CHF 20
    Assets:Cash

import subprocess
from datetime import datetime

format = "'%(cleared)\t%D\t%P\t%(quantity(scrub(display_amount)))\t%(join(note | xact.note))\n'"
query = "ledger -f file.dat csv Assets:Cash --csv-format " + format
runQuery = subprocess.check_output((query), shell=True).splitlines()
trx = [x.decode("utf-8").split("\t") for x in runQuery]
return datetime.strptime(trx[0][1],"%Y/%m/%d").month

Month of first transaction is 11

Read on /posts/parse_ledger-cli_using_python/

Comments

Nothing yet. Say the first thing.

    Sign in to join the conversation.