presto-report, a cli tool to automate the generation (and emailing) of prestocard.ca transit activity reports, mainly for expense purposes.
presto-report is a simple NodeJS app packaged in a Docker image alongside a full Chrome headless browser. It is based on zenika/alpine-chrome and uses puppeteer to crawl the Web and generate PDFs. It supports emailing PDFs with a [free] SendGrid API key.
What it does:
- Navigates to https://www.prestocard.ca/en/dashboard/card-activity & signs in;
- Picks a date range, transaction types(s) (default: 'card loads') and clicks 'View';
- Clicks 'Print' & saves as PDF;
- (Optional) Emails that PDF.
docker pull pndurette/presto-report
cat << EOF > .env
PRESTO_USER=youruser
PRESTO_PASS=yourpass
EOF
Define PRESTO_USER
and PRESTO_PASS
respectively as your prestocard.ca credentials (see .env.example
).
docker run --rm --privileged --env-file .env pndurette/presto-report --help
Last month's report to ./artifacts/<report>.pdf
:
Emailing is optional. Mount the /artifacts
directory from the container to access your report:
docker run --rm --privileged --env-file .env \
-v $(pwd)/artifacts:/artifacts \
pndurette/presto-report --lastmonth
June 2018's report to receipts@company.com
:
To email, you'll need a SendGrid API Key (with at least the 'Mail Send' scope—it's free for 100 emails/day) set to SENDGRID_API_KEY
in your .env
file
Some expensing systems (like Chrome River) that supports receipts emailing allows you to set the 'subjet' to the amount of the expense.
docker run --rm --privileged --env-file .env \
-v $(pwd)/artifacts:/artifacts \
pndurette/presto-report --year 2018 --month 06 \
--to receipts@company.com \
--from me@company.com \
--subject '$100'
Last month's report to receipts@company.com
Any CLI option opt
can be set via a PRESTO_<OPT>
environment variable in .env
(e.g. PRESTO_TO
, PRESTO_FROM
, etc.) as defaults. See .env.example
.
docker run --rm --privileged --env-file .env pndurette/presto-report --lastmonth
The error management in this piece of software is piss-poor at best. Effort was made to pre-validate the input, but that's about it. If it hangs, CTRL-C and check your parameters (username, password, api keys) but also the network, etc. Timeouts are also possible. Please note that is also my first forray into NodeJS.
This only supports PRESTO card accounts with one card set up as I don't have a second one to test.