reportwarrior
v0.3.1
Published
Tooling to create reports from TaskWarrior using Mozilla Nunjucks.
Downloads
40
Maintainers
Readme
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:
<h2>
<span style="font-weight: bold;background-color: orange;"> Pending </span>
<span> <i>HASS: program Volume control, from Audiolab M-DAC to TV</i></span>
</h2>
<table>
<tr>
<th>Priority</th>
<td>Low</td>
</tr>
</table>
<small>Task ref bfafac85-84d5-47ab-9d11-0db61c6fd57c</small>
<hr/>
<h2>
<span style="font-weight: bold;background-color: orange;"> Pending </span>
<span> <i>Buy bookshelves</i></span>
</h2>
<table>
<tr>
<th>Priority</th>
<td>Medium</td>
</tr>
</table>
<small>Task ref 55713ae1-9d75-48e9-ae28-800da70a4447</small>
<hr/>
<h2>
<span style="font-weight: bold;background-color: orange;"> Pending </span>
<span> <i>HASS: Add TV to HomeAssistant</i></span>
</h2>
<table>
<tr>
<th>Priority</th>
<td>Low</td>
</tr>
</table>
<small>Task ref 4a04082b-af4c-46e3-a9b6-c981243cd654</small>
<hr/>
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 = require('os');
const path = require('path');
module.exports = {
registerFilters: (njk) => {
njk.addFilter('priority', p => ({ 'H': 'High', 'M': 'Medium', 'L': 'Low' })[p])
},
paths: { templates: path.resolve(os.homedir(), '.reportwarrior/templates') },
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 "[email protected]: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 "[email protected]: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 "[email protected]: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/.$//')"