OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Pandas dataframe to markdown - add border lines to table in email as part of a Snowflake alert

  • Thread starter Thread starter Estrobelai
  • Start date Start date
E

Estrobelai

Guest
I have a stored procedure on Snowflake that is converting a table into HTML and adding it to an alert email (notification integration) so people across the business are aware of any failures or errors with any tasks or copy commands that we run into. This stored procedure below is working fine, but I am getting a table in the email body with no border lines:

Code:
CREATE OR REPLACE PROCEDURE ERRORS_ALERTS(
    email_integration_name STRING,
    email_address STRING
) 
RETURNS STRING
LANGUAGE PYTHON
RUNTIME_VERSION = 3.10
PACKAGES = ('snowflake-snowpark-python', 'pandas', 'tabulate')
HANDLER = 'main'
AS $$

import snowflake.snowpark
import pandas

def main(
  session: snowflake.snowpark.Session,
  email_integration_name: str,
  email_address: str
) -> str:
    table_pandas_df: pandas.DataFrame = session.table("logs").to_pandas()
    table_as_html: str = table_pandas_df.to_markdown(
      tablefmt="html",
      index=False
    )
    email_as_html: str = f"""
        <p>Today's loading errors report</p>
        <p>{table_as_html}</p>
    """
    success: bool = session.call(
      "SYSTEM$SEND_EMAIL",
      email_integration_name,
      email_address,
      'Daily loading errors report',
      email_as_html,
      'text/html'
    )

    return "Email sent successfully" if success else "Sending email failed"

$$;

Whenever I run the stored procedure above, I get an email with the table below in the body:

enter image description here

Any tips on how I can add some code to add border lines and enhance the formatting of this table?
<p>I have a stored procedure on Snowflake that is converting a table into HTML and adding it to an alert email (notification integration) so people across the business are aware of any failures or errors with any tasks or copy commands that we run into. This stored procedure below is working fine, but I am getting a table in the email body with no border lines:</p>
<pre><code>CREATE OR REPLACE PROCEDURE ERRORS_ALERTS(
email_integration_name STRING,
email_address STRING
)
RETURNS STRING
LANGUAGE PYTHON
RUNTIME_VERSION = 3.10
PACKAGES = ('snowflake-snowpark-python', 'pandas', 'tabulate')
HANDLER = 'main'
AS $$

import snowflake.snowpark
import pandas

def main(
session: snowflake.snowpark.Session,
email_integration_name: str,
email_address: str
) -> str:
table_pandas_df: pandas.DataFrame = session.table("logs").to_pandas()
table_as_html: str = table_pandas_df.to_markdown(
tablefmt="html",
index=False
)
email_as_html: str = f"""
<p>Today's loading errors report</p>
<p>{table_as_html}</p>
"""
success: bool = session.call(
"SYSTEM$SEND_EMAIL",
email_integration_name,
email_address,
'Daily loading errors report',
email_as_html,
'text/html'
)

return "Email sent successfully" if success else "Sending email failed"

$$;
</code></pre>
<p>Whenever I run the stored procedure above, I get an email with the table below in the body:</p>
<p><a href="https://i.sstatic.net/Tpq2Bt8J.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Tpq2Bt8J.png" alt="enter image description here" /></a></p>
<p>Any tips on how I can add some code to add border lines and enhance the formatting of this table?</p>
 

Latest posts

B
Replies
0
Views
1
Blundering Ecologist
B
Top