twital
stands for "This Week in the Aranda Lab", by the way. Creative naming is not my forte.
TL;DR: check out email_contents.txt
for a sample output.
Note: for security concerns, I have modified the script to remove several addresses. These addresses appears as "REDACTED", so you'll have to plug your own details to get it to work. I have also excluded client_secret.json, which is required for task #1.
There's basically three tasks:
- Parse lab Google Calendar.
- Find a way to email the text out.
- Set a timer to do it once every week.
Surprisingly NOT the hardest part of the project. #2 was a bigger PITA.
It's supposed to generate two files: .credentials
and client_secret.json
if it is unable to find these files on your system.
Note: I was unable to generate them on Bash: The text-mode authentication did not work for some reason. I had to run the code on Windows to authenticate via my browser to generate these two files, then move them over to my Debian system. -__-"
Once parsed, there's a lot of unexplained mojo in the script to deal with parsing dates and times. I've standardised the script to use a specific timezone (GMT+3) to properly output event start and end times.
I tried using Yahoo Mail and it didn't work. I guess there's a reason why Gmail is dominating the free email space.
(cron, by default, runs from ~, so one needs to cd into the folder containing the script.)
A few explanations of why I did certain things:
- Why wrap the email body with <pre> </pre> before sending it out?
- It's because Outlook defaults to viewing emails in HTML mode, which badly mangles the "Aranda Lab" header. The <pre> protects multiple space characters from getting merged into one. Blame HTML for this silliness.
- Why use command-line mail command (i.e. exim4) to do the emailing, instead of writing a script to do it?
- Laziness, and also because having the mail command set up properly on my own system allows me to email myself notifications (e.g. if I'm monitoring a script's output, I can get the output sent to me via email).