notify_error: Automated email report for use in exception catch.
defnotify_error(report_name, error_log, to_list: str):
""" :param to_list: List of emails to receive notification. :param report_name: Name of automated report. :param error_log: Raised exception or other error to report. """
Example Call
fromoutlookutilityimportnotify_errorimportosdeffoo():
raiseException('Error!')
try:
foo()
exceptExceptionase:
notify_error(f"{os.path.basename(__file__)}", e, "a@email.com")
default_table_style : Apply formatting to Pandas dataframe for use in email
defdefault_table_style(df, index: False):
""" Apply a default clean table style to pandas df.to_html() for use in email strings. :param index: Determines whether you want index displayed in the HTML. Defaults to False. :type index: Boolean :param df: Dataframe to apply the style to. :type df: Pandas Dataframe :return: HTML string for insertion in email. :rtype: string """
Example Call
fromoutlookutilityimportdefault_table_styleimportpandasaspdimportnumpyasnpdf=pd.DataFrame(np.random.randint(0,100,size=(15, 4)), columns=list('ABCD'))
test_message=f"""<HTML> <BODY> Email Text Here <br>{default_table_style(df,index=False)} <br> </BODY></HTML>"""
multi_table_style : Apply formatting to multiple Pandas dataframes for use in email
defmulti_table_style(df_list, index: False):
""" Apply a default clean table style to pandas df.to_html() for use in email strings. This version returns multiple tables stacked on top of each other with a line break inbetween. :param index: Determines whether you want index displayed in the HTML. Defaults to False. :type index: Boolean :param df_list: List of dataframes to return in html format. :type df: Pandas Dataframe :return: HTML string for insertion in email. :rtype: string """
Example Call
fromoutlookutilityimportmulti_table_styleimportpandasaspdimportnumpyasnpdf=pd.DataFrame(np.random.randint(0,100,size=(15, 4)), columns=list('ABCD'))
df_list= [df,df]
formatted_tables=multi_table_style(df_list,index=False)
test_message=f"""<HTML> <BODY> Email Text Here <br>{formatted_tables} <br> </BODY></HTML>"""