improve example of custom formatter
This commit is contained in:
parent
37893a9e9a
commit
3d63a581a4
|
@ -585,6 +585,8 @@ Formatter used for the :ref:`t-display` family of commands when no ``--format``
|
|||
argument is passed. Included formatters are explained in the
|
||||
:ref:`default-formatters` section, they are: chart, text, ical, csv, json, ids.
|
||||
|
||||
.. _formatter_search_paths:
|
||||
|
||||
formatter_search_paths
|
||||
......................
|
||||
|
||||
|
@ -871,27 +873,10 @@ for this formatter stored in the config file and formatted as JSON.
|
|||
Example
|
||||
.......
|
||||
|
||||
Suppose we have this config file:
|
||||
|
||||
.. code:: toml
|
||||
|
||||
database_file = "/home/user/.config/tiempo/database.sqlite3"
|
||||
round_in_seconds = 900
|
||||
append_notes_delimiter = " "
|
||||
formatter_search_paths = ["/home/user/.config/tiempo/formatters"]
|
||||
default_formatter = "text"
|
||||
auto_sheet = "dotfiles"
|
||||
auto_sheet_search_paths = ["/home/user/.config/tiempo/auto_sheets"]
|
||||
auto_checkout = false
|
||||
require_note = true
|
||||
week_start = "Monday"
|
||||
|
||||
[formatters.earnings]
|
||||
hourly_rate = 300
|
||||
currency = "USD"
|
||||
|
||||
then we can create the ``earnings`` formatter by placing the following file in
|
||||
``/home/user/.config/tiempo/formatters/earnings`` and making it executable:
|
||||
Let's create a simple ``earnings`` formatter. It is as easy as creating the
|
||||
following python script under the name ``earnings`` (no extension) inside one of
|
||||
the paths listed in your :ref:`formatter_search_paths` setting and marking it as
|
||||
executable (``chmod +x earnings``):
|
||||
|
||||
.. code:: python
|
||||
|
||||
|
@ -900,7 +885,7 @@ then we can create the ``earnings`` formatter by placing the following file in
|
|||
from datetime import datetime, timezone, timedelta
|
||||
from math import ceil
|
||||
|
||||
# Settings for this formatter passed as the first argument
|
||||
# Settings for this formatter are passed as the first argument
|
||||
config = json.loads(sys.argv[1])
|
||||
|
||||
reader = csv.DictReader(
|
||||
|
@ -929,6 +914,14 @@ then we can create the ``earnings`` formatter by placing the following file in
|
|||
|
||||
print(f'You have earned: ${earnings:.2f} {currency}')
|
||||
|
||||
You'll also need to add these settings to your config file:
|
||||
|
||||
.. code:: toml
|
||||
|
||||
[formatters.earnings]
|
||||
hourly_rate = 300
|
||||
currency = "USD"
|
||||
|
||||
Now if you run ``t display -f earnings`` you will get something like:
|
||||
|
||||
.. code:: text
|
||||
|
|
Loading…
Reference in New Issue