最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - Send code to teams group through webhooks - Stack Overflow

programmeradmin0浏览0评论

I want to send a custom message to teams that is going is looking like the image attached. I am doing it by this code in python. But I would the code part of my message to be formatted in sql and have the copy code button like the other image. I havent found any reference on how I should send this information. properly I have found regarding how to send the code.

    html_table = spark.sql(query+ " LIMIT 10").toPandas().to_html(index=False,justify='center',float_format="{:,.2f}".format).replace('<td>','<td style="text-align: center;">')

if num_outliers > 10:
  n = 10
else:
  n = num_outliers

html_message = f"""<strong>{CONS_CATALOG.upper()}.{CONS_SCHEMA_BUILD.upper()}.{CONS_TABLE_CONVIVA_HISTORICAL_COST.upper()}</strong><br>
<hr>
A total of {num_outliers} outliers has been detected on {date} for <em><a href="{CONS_TABLE_URL}">{CONS_CATALOG}.{CONS_SCHEMA_BUILD}.{CONS_TABLE_CONVIVA_HISTORICAL_COST}</a></em><br>
<br>The TOP {n} outliers are: <br> <br>
{html_table}
<br> To see the outliers run the following script on <em><a href="{CONS_TABLE_URL}">{CONS_CATALOG}.{CONS_SCHEMA_BUILD}.{CONS_TABLE_CONVIVA_HISTORICAL_COST}</a></em>: <br>
<pre>{query}
</pre>
payload ={"text":html_message,
        'parse_mode': 'HTML'
         }


# Set the headers for the request
headers = {
    "Content-Type": "application/json"
}


# Make the POST request
response = requests.post(CONS_TEAMS_WEBHOOK_URL, headers=headers, data=json.dumps(payload))

# Print the response
if response.status_code == 200:
    print("Alert created successfully:", response.json())
else:
    print("Failed to create alert:", response.status_code, response.text)

发布评论

评论列表(0)

  1. 暂无评论