Skip to content

ContentEmailOperator: rich HTML emails with Matplotlib graphs as images#451

Closed
patrickleotardif wants to merge 1 commit intoapache:masterfrom
patrickleotardif:content-email-operator
Closed

ContentEmailOperator: rich HTML emails with Matplotlib graphs as images#451
patrickleotardif wants to merge 1 commit intoapache:masterfrom
patrickleotardif:content-email-operator

Conversation

@patrickleotardif
Copy link
Contributor

(Intended as an initial draft since the current approach is pretty hacky <- @mistercrunch )

Usage in a DAG:

email = ContentEmailOperator(
        task_id='email',
        to=[
            'plt@rdif.me'
        ],
        subject='Report for {{ ds }}',
        template=os.path.join(cur_dir, 'email.html'),
        data={
            'by_type' : 'sql/by_type.sql',
            'all' : 'sql/all.sql'
        },
        variables={
            'ds' : '{{ ds }}'
        },
        default_args=args)

In this case email.html is a Jinja template with specific macros to generate the matplotlib images. The data dict is simply Presto queries now (but could be generalized).

e.g. email.html

<table>
    <tr bgcolor="ff5a5f" height="50px" width="775px">
        <td align="center" style="font-family: Tahoma, Arial, Verdana, sans-serif;font-size:18px;">
            <font color="white">
                Daily Report for {{ variables['ds'] }}
            </font>
        </td>
    </tr>

    <tr height="5px" ></tr>

    <tr> 
        <td>
            {{ lib.line_graph(data['events'], 'event_count','linechartnew','Events Per Day') }}
        </td>
    </tr>

    <tr height="10px" bgcolor="#ccc" align="right" style="font-family: Tahoma, Arial, Verdana, sans-serif;font-size:12px;">
        <td>
            <font color="white">
                brought to you by #data-engineering
            </font>
        </td>
    </tr>
</table>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this works only with Presto it should be named as such. I think it should be easy to generalize it to work with any hooks that has the required methods.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point.

@patrickleotardif
Copy link
Contributor Author

Closing for now since this is ancient

@landscape-bot
Copy link

Code Health
Repository health decreased by 0.02% when pulling b0cf5f5 on patrickleotardif:content-email-operator into dcad5c6 on airbnb:master.

@r39132
Copy link
Contributor

r39132 commented Mar 21, 2016

@patrickleotardif I was looking for email operator that provided matplotlib or highcharts like charts. If you ever tackle this again, I would be very interested in it!

@patrickleotardif
Copy link
Contributor Author

@r39132 Sounds good! I already have something similar to this commit running here. I think it just needs to be cleaned up and done a bit more thoughtfully before integrating here.

@r39132
Copy link
Contributor

r39132 commented Mar 21, 2016

Cool! Thx.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants