python-3.x - 如何在 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()
解决方案
尝试使用这个刚刚使用的 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()
推荐阅读
- html - 设置样式时切换时不显示 Div
- keyword - 如何使用 DOORS DXL 按关键字查找需求
- reactjs - React:检查不同组件中的元素是否重叠
- python - 从字典列表创建一个新字典
- excel - 复制 Excel RANK 公式而不更改结束引用
- css - 引导布局:嵌套在 div 内的 Img 不会对齐左边缘
- pdf - 文本更改为图形,在 PDF 中仍然可以选择?
- regex - 提取tableau中的第一行文本
- amazon-web-services - AWS 通过 IP 和 Mac 组合阻止?
- json - 如何使用正文中的外部数据通过 JSON 向 API 发出 PUT 请求?