0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Beancount/Favaで自分の出費を可視化する (できなかった)

Posted at

Beancount Fava

コツコツプレーンテキストで家計簿つけてるわけですが、やっぱりグラフとかみたいですよね?今日はそれです。

setup

必要なパッケージを入れます。favaはvisualization用のソフトウェアですが、Beancountという微妙に違うsyntaxを要求します。なのでledger2beancountという変換用のソフトも導入します。

$ sudo apt install python3-fava ledger2beancount

大量に依存パッケージが入りますが見なかったことにします。気に入らない人はvenv+pipとかで入れたらいいと思います。

conversion

自分の書いてるledgerファイルをまずprintコマンドで一つの巨大なファイルにします。

$ ledger -f root.ledger print > /tmp/inline.ledger

次にこれをBeancountにしてみます。

$ ledger2beancount /tmp/inline.ledger > /tmp/inline.beancount

なんかエラーがいくつか出ますが気にしないことにします。

visualization

 % fava /tmp/inline.beancount
Traceback (most recent call last):
  File "/usr/bin/fava", line 33, in <module>
    sys.exit(load_entry_point('fava==1.18', 'console_scripts', 'fava')())
  File "/usr/bin/fava", line 25, in importlib_load_entry_point
    return next(matches).load()
  File "/usr/lib/python3.9/importlib/metadata.py", line 77, in load
    module = import_module(match.group('module'))
  File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 790, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/usr/lib/python3/dist-packages/fava/cli.py", line 11, in <module>
    from fava.application import app
  File "/usr/lib/python3/dist-packages/fava/application.py", line 67, in <module>
    app.jinja_options["extensions"].append("jinja2.ext.do")
KeyError: 'extensions'

おっと、pipの出来損ないが入ってたみたいです。消してやり直し。

 % rm -rf ~/.local/lib/python3.9/site-packages/
 % fava /tmp/inline.beancount
Running Fava on http://localhost:5000

これをSSHのポートフォワーディングしつつ見ます... エラーだらけですね。

/tmp/inline.beancount 	14616 	syntax error, unexpected NUMBER, expecting end of file or EOL
/tmp/inline.beancount 	14621 	syntax error, unexpected NUMBER, expecting end of file or EOL
/tmp/inline.beancount 	20553 	Duplicate posting metadata field: KeyValue(key='payee', value='CH')
/tmp/inline.beancount 	22252 	syntax error, unexpected EOL
/tmp/inline.beancount 	22338 	syntax error, unexpected EOL
/tmp/inline.beancount 	22452 	syntax error, unexpected EOL
/tmp/inline.beancount 	14665 	Balance failed for Assets:Banks:Sony:Gaika: expected 33.50 CHF != accumulated 0 CHF (33.50 too little)

1400個もエラーが出てます。ちょっとめんどくさいですね。見てみたところ、タグの期待するフォーマットがより厳格だったり、balanceが一日複数あったら警告が出るみたいで、これは私の場合かなり致命的です。諦めて自分で可視化するかフォーマットをなんとか適合させるか。私はとりあえずほかを探します。

% sudo apt purge python3-fava ledger2beancount
% sudo apt autoremove --purge
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?