ReportWarrior
Tooling to create reports from TaskWarrior using Mozilla Nunjucks. This tool is ofcourse not limited to HTML. You can generate Markdown reports as well.
Installation
$ npm install -g reportwarrior
Usage
First usage will install configuration in ~/.reportwarrior.
$ task export | reportwarrior -f basic$ task export | reportwarrior --flow clientAbc
Example output:
Pending HASS: program Volume control, from Audiolab M-DAC to TV Priority Low Task ref bfafac85-84d5-47ab-9d11-0db61c6fd57c Pending Buy bookshelves Priority Medium Task ref 55713ae1-9d75-48e9-ae28-800da70a4447 Pending HASS: Add TV to HomeAssistant Priority Low Task ref 4a04082b-af4c-46e3-a9b6-c981243cd654
Configuration
In the configuration, as seen as below, there are options to create your own titles, recipients and use specific templates per flow. In the configuration, you could even define momentjs
-filters for Mozilla Nunjucks or use momentjs
in your configuration. To do that, first run npm init && npm install --save moment
in your ~/.reportwarrior
-directory.
const os = ;const path = ; moduleexports = { njk } paths: templates: path flows: basic: template: "basic.html.njk" email: template: "email.html.njk"
Templates
Templates are using Mozilla Nunjucks. You can register new Filters in the configuration file.
Use with email
IMAP
Taskwarrior can easily be used in combination with IMAP. I personally use this to create a Draft on the remote server, to be able to check it and send it later on. You can even make a cronjob out of it.
$ TMP=$(mktemp); task export | reportwarrior -f email > $TMP && curl --url "imaps://imap.gmail.com:993/%5BGmail%5D%2FDrafts" --user "user@gmail.com:password" -T $TMP && rm $TMP
In this example, please replace the URL, TaskWarrior filters, username and password appropriately. You can replace the encoded suffix [Gmail]Drafts
with any you want. For a IMAP representation of labels:
$ curl --url "imaps://imap.gmail.com:993/" --user "user@gmail.com:password"
In Gmail, you can easily create new labels. Those are usable by IMAP clients such as cURL.
SMTP
Due to somewhat more complexity (we need to insert the sender and receiver and still maintain the template as is), we use a somewhat different oneliner for sending email using SMTP:
$ export TMP=$(mktemp); task export | reportwarrior -f email > $TMP && curl -kv --url "smtps://smtp.gmail.com:465/" --user "user@gmail.com:password" --mail-from "$(grep -P "^From:.*<(.*)>" $TMP | grep -o "<.*>" | sed -e 's/^.//' -e 's/.$//')" --mail-rcpt "$(grep -P "^To:.*<(.*)>" $TMP | grep -o "<.*>" | sed -e 's/^.//' -e 's/.$//')" -T $TMP
The chained grep
and sed
are responsible for optaining the From
and To
header from the generated output. I hope I will find an easier way to do this, but this works for now.
--mail-from "$(grep -P "^From:.*<(.*)>" $TMP | grep -o "<.*>" | sed -e 's/^.//' -e 's/.$//')"