Parse ledger-cli using python
#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