aboutsummaryrefslogtreecommitdiff
path: root/README.md
blob: 3a327ea8332a1b99cf06dedad45d695ce968beb1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# Ledger.py

A simple implementation of [ledger-cli](https://github.com/ledger/ledger). This
implementation only covers a few commands of the original ledger-cli. This
project is only for educational purposes. It does not provide any advantages
over the original project.

# Usage

You can use this program as if it was the original **ledger-cli**, but with a
selected group of flags and commands:
```
./ledger.py [-h] [-v] [-S value-expression] [--price-db FILE] [-f FILE] Action [Action ...]
```

- `-h`: Displays the usage and description of the program.
- `-v`: Displays the current version of the program.
- `-S` or `--sort`: Sorts the entries. See the [`--sort` section](#sort) for
  more details.
- `--price-db`: Currently it has no purpose. See the [`--price-db`
  section](#price-db) for more details.
- `-f` or `--file`: Use the specified file as an input.
- `Action`: The first word will be our *verb*. The *verb* describes what our
  program will output. It currently can be `register`, `balance` or `print`.

  The following words will be our *filters* for which accounts we'll work with.
  See the [filters section](#filters) for more details.

Let's see this commands in more detail.


# Filters

Filters can be applied to just see a subset of all of our accounts. To use
filters, we'll start by describing our keywords:

### And

```
{x} and {y}
```

This way, we can filter accounts if they have the text `{x}` and `{y}` in them.

> Examples:
> 
> ```
> Expenses and Amazon
> ```
> ```
> Income and Job and Encora
> ```

### Or

```
{x} or {y}
```
```
{x} {y}
```

Both ways work. We can filter accounts if they have either `{x}` or `{y}`.

> Examples:
> ```
> Assets Liabilities
> ```
> ```
> Assets and (Bank or Wallet)
> ```

### Not

```
not {x}
```

Filter accounts that DO NOT have `{x}` in them.

> Examples:
> ```
> (Liabilities and not Rent) or Expenses
> ```
> ```
> Expenses and not (Drinks or Food)
> ```

### Regex

As you've just read. Every word is treated as a regex. For this project, we are
using [Python's regex](https://docs.python.org/3/library/re.html). Feel free to
experiment with this function. The only restriction is to not use spaces, as
they are our limiters for keywords and such.

> Examples:
> ```
> Income and [^:]+:[^:]+:[^:]+
> ```
> ```
> ^Expenses and not .*tion$
> ```

~~Sorry for my poor examples. I don't know about finances. ;-;~~


# `--file`

This flag can be used multiple times. It indicates the ledger file(s) we will be
working on. ~~If no file is specified, the program will read from standard input
(`stdin`).~~ ***NOT YET IMPLEMENTED.***


# `--sort`

**The `--sort` flag will always sort in ascending order.** We can sort our
entries in two different ways:

- `date` or `d`: Sort every entry given the date of the transaction.
- `amount` or `a`: Sort given the amount of the transaction. **This breaks
  entries into individual transactions.**

## It doesn't work on `balance`

The `--sort` flag will only make changes on the outputs of `register` and
`print`. The verb `balance` will **always** print in alphabetical order.


# `--price-db`

It points to the file that contains our prices history.

## It doesn't work well alone

The original flag for `--price-db` is commonly used alongside other flags such
as `-V` or `--market`, that uses the prices history to convert all amounts into
our default currency. That's why currently this command doesn't have any
function to it. It's yet to know how we will work with this flag.


# Examples

```
$ ./ledger.py -f index.ledger -S d register Bank  
11-Nov-21 Payment for hard.. Bank:Paypal                  $350.00      $350.00
12-Jul-01 Partial payment .. Bank:Paypal                  $100.00      $450.00
12-Nov-16 Sold some bitcoins Bank:Paypal                   $42.21      $492.21
12-Nov-29 Purchased bitcoins Bank:Paypal                 $-300.00      $192.21
```

```
$ ./ledger.py -f index.ledger --sort a print .\*coin  # In ZSH, the `*` must be escaped.
2013/02/20 Purchased reddit gold for the year
    Asset:Bitcoin Wallet                  -10.00 BTC

2012/11/16 Sold some bitcoins
    Asset:Bitcoin Wallet                   -3.50 BTC

2012/11/29 Purchased bitcoins
    Asset:Bitcoin Wallet                   15.00 BTC
```

```
$ ./ledger.py --file index.ledger bal Bank: Expense:
             $192.21  Bank:Paypal
           10.00 BTC
              $10.00  Expense
              $10.00    Favor
           10.00 BTC    Web Services:Reddit
--------------------
           10.00 BTC
             $202.21
```