python實(shí)現(xiàn)釘釘機(jī)器人自動(dòng)打卡天天早下班
一,新建釘釘機(jī)器人
1.釘釘群右上角點(diǎn)擊群設(shè)置,選擇智能群助手,點(diǎn)擊添加機(jī)器人,選擇自定義機(jī)器人;

2.給機(jī)器人起個(gè)名字,消息推送開(kāi)啟,復(fù)制出 webhook,后面會(huì)用到,勾選自定義關(guān)鍵詞,填寫(xiě)關(guān)鍵詞(關(guān)鍵詞可以隨便填寫(xiě),但是一定要記住,后面會(huì)用);


二,釘釘機(jī)器人發(fā)送消息
url 就是創(chuàng)建機(jī)器人時(shí)的 webhook,data 中的 atMobiles 可填寫(xiě)多個(gè)手機(jī)號(hào),發(fā)送的消息會(huì)直接 @ 這個(gè)人,text 的 content 里面一定要加上創(chuàng)建機(jī)器人時(shí)設(shè)置的關(guān)鍵詞,msgtype 意思時(shí)文本格式,也可以 link 格式,就可以放鏈接了;
def send_text(self):
url = "https://oapi.dingtalk.com/robot/send?access_token=43c4dab2ac31125e605c458b4b9561a73"
headers = {'Content-Type': 'application/json'}
data = {"at": {"atMobiles":["18206264857"],"atUserIds":["user123"],"isAtAll": False},
"text": {"content":"砍價(jià)小程序接口自動(dòng)化測(cè)試"},"msgtype":"text"},"msgtype":"text"}
requests.post(url,headers=headers,data=json.dumps(data))
三,釘釘機(jī)器人實(shí)際的應(yīng)用
1.監(jiān)控接口自動(dòng)化結(jié)果

實(shí)現(xiàn)思路是:jenkins 定時(shí)執(zhí)行自動(dòng)化——執(zhí)行完后生成 html 報(bào)告——BeautifulSoup 模塊解析 html 報(bào)告——發(fā)送釘釘消息
如下代碼:
解析 html 的模塊:
from common.handle_path import html_path
from bs4 import BeautifulSoup
class GetHtml:
"""
讀取測(cè)試報(bào)告,解析html 獲得測(cè)試用例總數(shù),通過(guò)數(shù)等,發(fā)送到釘釘
"""
def get_total(self):
with open(html_path, "r", encoding="utf-8") as f:
file = f.read()
soup = BeautifulSoup(file, 'html.parser') # 使用BeautifulSoup庫(kù)解析網(wǎng)頁(yè)內(nèi)容
item = soup.find_all("p")[1].string # 使用BeautifulSoup庫(kù)的標(biāo)簽方法找到你需要的內(nèi)容
return str(item)
def get_pass(self):
with open(html_path, "r", encoding="utf-8") as f:
file = f.read()
soup = BeautifulSoup(file, 'html.parser') # 使用BeautifulSoup庫(kù)解析網(wǎng)頁(yè)內(nèi)容
item = soup.find_all("span",class_="passed")[0].string # 使用BeautifulSoup庫(kù)的標(biāo)簽方法找到你需要的內(nèi)容
return str(item)
def get_skipped(self):
with open(html_path, "r", encoding="utf-8") as f:
file = f.read()
soup = BeautifulSoup(file, 'html.parser') # 使用BeautifulSoup庫(kù)解析網(wǎng)頁(yè)內(nèi)容
item = soup.find_all("span",class_="skipped")[0].string # 使用BeautifulSoup庫(kù)的標(biāo)簽方法找到你需要的內(nèi)容
return str(item)
def get_failed(self):
with open(html_path, "r", encoding="utf-8") as f:
file = f.read()
soup = BeautifulSoup(file, 'html.parser') # 使用BeautifulSoup庫(kù)解析網(wǎng)頁(yè)內(nèi)容
item = soup.find_all("span",class_="failed")[0].string # 使用BeautifulSoup庫(kù)的標(biāo)簽方法找到你需要的內(nèi)容
return str(item)
def get_error(self):
with open(html_path, "r", encoding="utf-8") as f:
file = f.read()
soup = BeautifulSoup(file, 'html.parser') # 使用BeautifulSoup庫(kù)解析網(wǎng)頁(yè)內(nèi)容
item = soup.find_all("span",class_="error")[0].string # 使用BeautifulSoup庫(kù)的標(biāo)簽方法找到你需要的內(nèi)容
return str(item)
def get_xfailed(self):
with open(html_path, "r", encoding="utf-8") as f:
file = f.read()
soup = BeautifulSoup(file, 'html.parser') # 使用BeautifulSoup庫(kù)解析網(wǎng)頁(yè)內(nèi)容
item = soup.find_all("span",class_="xfailed")[0].string # 使用BeautifulSoup庫(kù)的標(biāo)簽方法找到你需要的內(nèi)容
return str(item)
def get_xpassed(self):
with open(html_path, "r", encoding="utf-8") as f:
file = f.read()
soup = BeautifulSoup(file, 'html.parser') # 使用BeautifulSoup庫(kù)解析網(wǎng)頁(yè)內(nèi)容
item = soup.find_all("span",class_="xpassed")[0].string # 使用BeautifulSoup庫(kù)的標(biāo)簽方法找到你需要的內(nèi)容
return str(item)
if __name__ == '__main__':
t = GetHtml()
t.get_xpassed()
如下代碼:
發(fā)送釘釘消息的模塊:
import requests
import json
from common.handle_readhtml import GetHtml
class SendMassage:
"""
發(fā)送測(cè)試結(jié)果到釘釘群
"""
result = GetHtml()
total = result.get_total()
passed = result.get_pass()
skipped = result.get_skipped()
failed = result.get_failed()
error = result.get_error()
xfailed = result.get_xfailed()
xpassed = result.get_xpassed()
def send_text(self):
url = "https://oapi.dingtalk.com/robot/send?access_token=43c4dab2ac3152e605c458b4b9561a73"
headers = {'Content-Type': 'application/json'}
data = {"at": {"atMobiles":["18206233880"],"atUserIds":["user123"],"isAtAll": False},
"text": {"content":"砍價(jià)小程序接口自動(dòng)化測(cè)試 \n total : {}\n passed : {},\n skipped : {},\n failed : {},\n error : {},\n xfailed : {},\n xpassed : {}".format(self.total,self.passed,self.skipped,self.failed,self.error,self.xfailed,self.xpassed)},"msgtype":"text"}
requests.post(url,headers=headers,data=json.dumps(data))
if __name__ == '__main__':
s = SendMassage()
s.send_text()
jenkins 配置的 shell 為:
先執(zhí)行接口自動(dòng)化腳本,等待一會(huì)然后發(fā)送釘釘消息;
${PYTHON} main.py
sleep 100
${PYTHON} handle_dingding.py
接口自動(dòng)化發(fā)釘釘群消息還可以再優(yōu)化,比如可以加上斷言失敗的錯(cuò)誤日志等;

2,監(jiān)控 qa 環(huán)境錯(cuò)誤日志
這里貼上周游大佬的一篇博客:http://chabaoo.cn/article/250972.htm
此處發(fā)送的 qq 郵件,消息查看不方便,且不好共享,可以優(yōu)化為發(fā)釘釘群消息,然后將開(kāi)發(fā)也拉到群里,提高效率;
3,jira 上有釘釘機(jī)器人插件,可以每天發(fā)送消息 @ 某某開(kāi)發(fā) 還有 N 個(gè)待處理 bug,@ 某某測(cè)試 還有 N 個(gè)待驗(yàn)證 bug,以及監(jiān)控看板指標(biāo)達(dá)到閾值報(bào)警等;
以上就是python實(shí)現(xiàn)釘釘機(jī)器人自動(dòng)打卡天天下早班的詳細(xì)內(nèi)容,更多關(guān)于python釘釘機(jī)器人打卡的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
基于tensorflow指定GPU運(yùn)行及GPU資源分配的幾種方式小結(jié)
今天小編就為大家分享一篇基于tensorflow指定GPU運(yùn)行及GPU資源分配的幾種方式小結(jié),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-02-02
利用Python過(guò)濾相似文本的簡(jiǎn)單方法示例
這篇文章主要給大家介紹了關(guān)于利用Python過(guò)濾相似文本的簡(jiǎn)單方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-02-02
python基于物品協(xié)同過(guò)濾算法實(shí)現(xiàn)代碼
這篇文章主要為大家詳細(xì)介紹了python基于物品協(xié)同過(guò)濾算法實(shí)現(xiàn)代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-05-05
Django定制Admin頁(yè)面詳細(xì)實(shí)例(展示頁(yè)面和編輯頁(yè)面)
django自帶的admin因?yàn)楣δ芎蜆邮奖容^簡(jiǎn)陋,常常需要再次定制,下面這篇文章主要給大家介紹了關(guān)于Django定制Admin頁(yè)面(展示頁(yè)面和編輯頁(yè)面)的相關(guān)資料,需要的朋友可以參考下2023-06-06
Pytorch 如何實(shí)現(xiàn)LSTM時(shí)間序列預(yù)測(cè)
本文主要基于Pytorch深度學(xué)習(xí)框架,實(shí)現(xiàn)LSTM神經(jīng)網(wǎng)絡(luò)模型,用于時(shí)間序列的預(yù)測(cè)2021-05-05
Python 實(shí)現(xiàn)簡(jiǎn)單的電話本功能
這篇文章主要介紹了Python 實(shí)現(xiàn)簡(jiǎn)單的電話本功能的相關(guān)資料,包括添加聯(lián)系人信息,查找姓名顯示聯(lián)系人,存儲(chǔ)聯(lián)系人到 TXT 文檔等內(nèi)容,十分的細(xì)致,有需要的小伙伴可以參考下2015-08-08

