前言
# coding:utf-8
import requests
import json
# 这里的地址是机器人的地址webhook地址,自行申请使用
url = 'https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxx'
headers = {'Content-Type': 'application/json'}
# 参数内容
data = {"msgtype":
"text","text":
{"content":"缺陷名称:今天你有学习吗?"},
"at": {
# 要@的人
"atMobiles": " ",
# 是否@所有人
"isAtAll": False
}
}
r = requests.post(url,headers=headers,data=json.dumps(data))
print(r.status_code)
print(r.text)
import pymysql
# 连接数据库
count = pymysql.connect(
host = '127.0.0.1', # 数据库地址
port = 3306, # 数据库端口号
user='root', # 数据库账号
password='821006052', # 数据库密码
db= 'zentao', # 数据库表名
charset = 'gbk' # 中文乱码
)
# 完成mysql数据库实例化
db = count.cursor()
# sql语句
sql = 'select title from zt_bug'
# 执行sql
a = db.execute(sql)
# 查找所以内容
result = db.fetchall()
print(result)
# coding:utf-8
import pymysql
import requests
import json
# 连接数据库
def MYsql(sql):
a = []
count = pymysql.connect(
host = '127.0.0.1', # 数据库地址
port = 3306, # 数据库端口号
user='root', # 数据库账号
password='821006052', # 数据库密码
db = 'zentao') # 数据库表名
# 创建数据库对象
db = count.cursor()
# 写入SQL语句
sql_ = sql
# 执行sql命令
db.execute(sql_)
# 获取全部的查询内容
restul = db.fetchall()
# 将查询的结果添加到列表中
for i in restul:
a.append(i[0])
db.close()
return a
def DingDing(text):
# 钉钉机器人的webhook的地址
url = 'https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxx'
headers = {'Content-Type': 'application/json'}
data = {"msgtype":
"text", "text":
{"content": "缺陷名称:以下是缺陷标题%s" %text},
"at": {
# 要@的人
"atMobiles": "",
# 是否@所有人
"isAtAll": False
}
}
r = requests.post(url, headers=headers, data=json.dumps(data))
print(r.status_code)
print(text)
result = MYsql("select title from zt_bug")
DingDing(result)