首页 > 解决方案 > 如何在 pymsteams API 的 myTeamsMessage.title 中打印当前日期

问题描述

我正在尝试通过 Python“pymsteams”API 发送自动消息,但我被困在一个地方。我想在我的自动化团队消息的标题中设置当前日期,但无法做到。有人能帮我一下吗。为了更清楚,我分享了我的代码。谢谢!!

import pymsteams
from datetime import date
 
# You must create the connectorcard object with the Microsoft Webhook URL
myTeamsMessage = pymsteams.connectorcard("<<Webhook url passing here>>")

today = date.today()
d1 = today.strftime("%d/%m/%Y")
# Add text to the message.
myTeamsMessage.title("d1- Americas Virtual Stand-up")
myTeamsMessage.text("this is my text")

# send the message.
myTeamsMessage.send()

标签: python-3.xmicrosoft-teams

解决方案


尝试使用这个刚刚使用的 Python3 的 f-Strings

import pymsteams
from datetime import date
 
# You must create the connectorcard object with the Microsoft Webhook URL
myTeamsMessage = pymsteams.connectorcard("<<Webhook url passing here>>")

today = date.today()
d1 = today.strftime("%d/%m/%Y")
# or user this formate
# d1 = today.strftime("%d-%m-%Y")
# Add text to the message.
myTeamsMessage.title(f"{d1} - Americas Virtual Stand-up")
myTeamsMessage.text("this is my text")

# send the message.
myTeamsMessage.send()

推荐阅读