Daily Homeroom Attendance Report
Automatically email a breakdown of statuses every day
Last updated
Automatically email a breakdown of statuses every day
Last updated
With the following input:
The date for which to report on, ex 2023-02-15
A subject for the email, ex "Daily attendance report"
List of comma-seperated emails to send to
An HTML template
Credentials to use smtp connection
Host, username, password, port
For a Google account:
Create an app password
Can email the following sample output:
The script to run the daily attendance report is the following:
Where:
{0}
is the date for which to report on
{1}
is the Subject of the email
{2}
is the /path/to/template.html file
{3}
list of emails
For example:
You will notice the above command does not include any SMTP server information. The way to provide these inputs is via shell environment variables. The steps are:
Create a file with the below contents
Replace those values with your real values
Save to a path location
Load those environment variables into the shell, with source /path/to/file
Example file:
If you are using Google and would like to login as a user, go to Manage Account —> Security —> App passwords. This is the password to use above, not your user login. Help article on App Passwords.
One of the inputs is a path to a template file. You can either use the simple one for testing, or you can customize it extensively. In addition, you can find the template used to generate the sample above below "Default template".
The template is written in jinja templating language, which is a cross between html and Python. It is a convenient way to include both presentation information, such as colors, and logical parameters, such as for loops, into the same file.
This will render a simple html table
under the Testing header.
The following uses the business logic possible with python-like syntax, such as for
loops, along with style tags.
Please see customization below to tweak or bulid your own.
The above describes how to execute it from the command line directly. To run it every day, a cron job can be installed. Instructions for this task can depend on which system you are using, but briefly:
Use crontab -e
to edit the cron table. Every line in the file is one task
A cron job executes in a secure environment, different from the command line directly. That means you need to write the full path.
Here is an example of the daily attendance report being sent every weekday at 4:05 pm:
The template can be coded in jinja's template language, which just means you can use both html, css, and a simple python-like syntax to build the presentation and the business logic needed for the intended output.
Please note that styling information in an email with html is not the same as doing so in the browser. Here is one example of a good resource that explains some of the specific techniques to use when styling email with hand-written html.
The variable data
is available in the template file, that has the following keys:
data.subject
The subject passed via the script as a string
{{ data.subject }}
data.today
Python datetime.today instance of today's date according to the host server
data.table
The data converted into html via pandas
.
{{ data.table }}
data.df
The raw pandas
dataframe.
The mbpy run scripts daily_homeroom_attendance
is actually short-hand script for a longer, harder-to-type sequence. Users can re-write for their own use cases.