Then I store the media in this folder with a convenient name so it can easily rendered with jinja2. Usually I create a parent directory in the web server dedicated for the report and a subdirectory for each execution. Create, if necessary, additional media to be inserted in the email (in my case just images).I’ll also store this dictionary in a xcom variable. Create a dictionary with the report KPIs and data wich will be used to render the mjml template.This task is very dependent on each use case, but in essence it has two aims: Extract report KPIs and generate media files Note that it also stores the report public url in a xcom variable (it will be used later). Upload_to_owncloud_task = OwncloudUploadFileOperator( With the python client library for owncloud it’s easy to write a custom airflow hook/operator, so this task is as simple as: I use a private instance of owncloud to share my reports. It is not necessary to change these tasks, just make sure to leave the output report file (pdf, csv, excel, etc.) in a handy place.Īdding a validation box could prevent sending wrong reports when there is some kind of anomaly in the data. I’ll also schedule this report so it’s going to be automatically run each month. I’m going to create a DAG with implements all the needed tasks to generate the report, the email summary and send the email. Let’s automate with a DAGĪs I mentioned before I’ll use Airflow to run and manage this workflow. Example of subject line encoding with emojis. If you want to include emojis, you can use a subject line assistant tool to encode the subject. The key point is to create a mjml template using jinja2 syntax (as in flask or django) to build the dynamic parts of the report. The mjml site includes a very good documentation, tester, examples, etc. This is a straightforward step if you have worked before with web frontend frameworks, as bootstrap for instance. Stack to create and schedule the email reports. (Optional) A subject line assistant tool, I use this one.owncloud: this is where I actually will upload the full report. This is how I’ll add dynamic capabilities to a static mjml template.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |