A small tools for arrange beancount files
Project description
beansieve 账单整理工具
beansieve 是一个用于整理 beancount 账本的小工具。这个工具主要实现以下两个功能:
- 通过
--type aggregate将账单中包含特定账户的条目放到一个新账本文件中。 - 通过
--type archive将特定时间范围内的 Transaction 条目保留到一个新账本文件中。
安装
pip install beansieve
一些术语
type:操作类型,即aggregate按账户拆分账本或archive按时间范围归档账本;source:源文件,即要操作的账本文件;dest:目标文件,即新生成的账本文件的保存目录;rule:使用aggregate时用于指定聚合规则;keep:使用archive时用于指定保留时间范围。
Structure 输出文件的结构
该工具运行会重新组织账本文件,组织规则如下:
── account.beancount # 账户相关指令,即 `open` 和 `close`
├── commodity.beancount # commodity 指令
├── custom.beancount # custom 指令(如 fava 中提供的 balance 指令)
├── document.beancount # document 指令
├── event.beancount # event 指令
├── history.beancount # 如果使用 `archive`,则 `keep` 范围外的 Transaction 会被移动到此文件夹中
├── main.beancount # 主账本文件,include 其他账本文件,如果使用 `archive` 则会包含 `keep` 范围内的 Transaction,如果使用 `aggregate` 则未匹配上的 Transaction 文件会被移动到此文件
├── note.beancount # note 指令
├── price.beancount # price 指令
├── <key>.beancount # 使用 `aggregate` 时按 `rule` 拆分出来的账本
└── query.beancount # query 指令
aggregate 的用法
使用 aggregate 将账单中包含特定账户的条目放到一个新账本文件中。
通过使用 --rule 设置账户匹配规则,支持设置多种规则,单条规则的格式为 <key>:<pattern>,其中 <key> 为文件名称,<pattern> 为一个用于匹配账户名称的正则表达式。如果有多条规则则使用 , 分割匹配规则。
例如下面的脚本会将 :
- posting 中账户名称匹配
Income:US:ETrade:.*的 Transaction 移动到Etrade.beancount文件; - posting 中账户名称匹配
Income:US:Babble:Salary的 Transaction 移动到Payroll.beancount文件; - 其他的 Transaction 移动到
main.beancount文件; - 其他的 Directive 会按照 Structure 规则移动到特定的文件中。
# generate sample beancount files
bean-example > example.beancount
bean-report example.beancount balances > example-balances.txt
# aggregate
rm -rf example_aggregate
python -m beansieve \
--type aggregate \
--source "example.beancount" \
--dest "example_aggregate" \
--rule "Etrade|Income:US:ETrade:.*,Payroll|Income:US:Babble:Salary"
bean-report example_aggregate/main.beancount balances > example_aggregate-balances.txt
archive 的用法
使用 archive 能够保留将特定时间范围内的 Transaction 条目保留到 main.beancount 文件中,时间范围外的 Transaction 会被移动到 archive.beancount 文件中。
其中 --keep 用于指定从当前时刻其回溯的时间范围,比如 1d 表示自当前时刻起前 1 天的 Transaction 会被保留到 main.beancount 文件中,1w 则保留前 7 天的条目,1m 保留前 30 天的条目。
例如下面的脚本会将:
- 从当前时刻起前 7 天的 Transaction 移动到
main.beancount文件; - 其他 Transaction 移动到
archive.beancount文件; - 其他的 Directive 会按照 Structure 规则移动到特定的文件中。
# generate sample beancount files
bean-example > example.beancount
bean-report example.beancount balances > example-balances.txt
rm -rf example_archive
python -m beansieve \
--type archive \
--source "example.beancount" \
--dest "example_archive" \
--keep 7d
bean-report example_archive/main.beancount balances > example_archive-balances.txt
其他说明
- 这个工具不能保证输入(
--source)文件结构的完整性,因此如果有使用include拆分账本文件的习惯,请先确保你认同Structure的拆分规则; aggregate和archive这两个命令不能同时使用,因为对我而言只是当有拆分 Transaction 的时候才会使用aggregate拆分账本,更多时候是通过archive来确保最近一段时间的账本文件(main.beancount)足够精简;- 使用前做好备份,以防止数据丢失,在使用前后使用 bean-report 生成 balance 报表进行对比,可以确保转换无误。
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file beansieve-0.1.1.tar.gz.
File metadata
- Download URL: beansieve-0.1.1.tar.gz
- Upload date:
- Size: 12.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f48bced390ee0c01bf020b9ab9c822411fdea10a5a914fd1317e87e19d8c9f3d
|
|
| MD5 |
4810a988ba7e7bd036d74eb6cca8c4e4
|
|
| BLAKE2b-256 |
63bef6f06a674771c48a2740b0055e919981f7cb7adeac390b2497a90e3053d8
|
File details
Details for the file beansieve-0.1.1-py3-none-any.whl.
File metadata
- Download URL: beansieve-0.1.1-py3-none-any.whl
- Upload date:
- Size: 16.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d319fb50abd5830b732a31b683c79439b7a69cfe1590f334acf689081bbcf5ca
|
|
| MD5 |
6e2d9852ab2971e7d9ad51793b497ad8
|
|
| BLAKE2b-256 |
7331c300da24603761714676a6848fb6fe86d1246136c4cfcbbd6d6000d156d5
|