下面是我的Python代码。基本上,它连接到SQL Server数据库,并获得一个通知列表,以便在空闲通道上发布。多个通知-如果它们的时间在近距离内-有时作为消息一起发布到Slack通道
当前输出为
User John submitted new notification. Link:
或
User John submitted new notification. Link:
User Jane submitted new notification. Link:
User Max submitted new notification. Link:
Python代码:
import requests
import json
import adodbapi
import adodbapi.ado_consts as adc
import adodbapi.is64bit as is64bit
sqlconn = adodbapi.connect('Provider=SQLNCLI11.1;Integrated Security=SSPI;Persist Security
Info=False;Initial Catalog="MyDatabase";Data Source=localhost,1360');
cur = sqlconn.cursor()
cur.execute('''
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
DECLARE @PostedOn datetime
SELECT @PostedOn=LastChecked FROM Notifications
select Email,a.PostedOn, '<https://www.website.com/' +CASE WHEN a.QuestionId IS NOT NULL THEN
'question' ELSE 'article' END+'/'+CONVERT(varchar,COALESCE(A.questionId,A.ArticleId))+'|Link>'
from UserProfile u
inner join answer a on a.UserId=u.UserId
where exists(select * from Topic et where et.UserId=u.UserId)
AND u.IsExpert=1
AND A.Postedon>@PostedOn
update Notifications
set LastChecked=GETDATE()
''')
sqlconn.commit()
url = 'http://ipaddress:port/bot/chatsecrets/notification-network'
headers = {'content-type': 'application/json'}
hasrows=0
postlist=''
template ='''User {0} submitted new notification. {1}:'''
for row in cur.fetchall():
postlist = postlist +'\n'+template.format(row[0],row[2])
hasrows=1
if hasrows:
response = requests.post(url, data=json.dumps({'secret': postlist}), headers=headers)
print (postlist)
我想配置代码,以便bot可以为每个新通知向Slack发送一条新消息,而不是收集通知列表并将其作为批量更新发送
目前没有回答
相关问题 更多 >
编程相关推荐