python實(shí)現(xiàn)釘釘機(jī)器人自動打卡天天早下班
一,新建釘釘機(jī)器人
1.釘釘群右上角點(diǎn)擊群設(shè)置,選擇智能群助手,點(diǎn)擊添加機(jī)器人,選擇自定義機(jī)器人;
2.給機(jī)器人起個名字,消息推送開啟,復(fù)制出 webhook,后面會用到,勾選自定義關(guān)鍵詞,填寫關(guān)鍵詞(關(guān)鍵詞可以隨便填寫,但是一定要記住,后面會用);
二,釘釘機(jī)器人發(fā)送消息
url 就是創(chuàng)建機(jī)器人時(shí)的 webhook,data 中的 atMobiles 可填寫多個手機(jī)號,發(fā)送的消息會直接 @ 這個人,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à)小程序接口自動化測試"},"msgtype":"text"},"msgtype":"text"} requests.post(url,headers=headers,data=json.dumps(data))
三,釘釘機(jī)器人實(shí)際的應(yīng)用
1.監(jiān)控接口自動化結(jié)果
實(shí)現(xiàn)思路是:jenkins 定時(shí)執(zhí)行自動化——執(zhí)行完后生成 html 報(bào)告——BeautifulSoup 模塊解析 html 報(bào)告——發(fā)送釘釘消息
如下代碼:
解析 html 的模塊:
from common.handle_path import html_path from bs4 import BeautifulSoup class GetHtml: """ 讀取測試報(bào)告,解析html 獲得測試用例總數(shù),通過數(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庫解析網(wǎng)頁內(nèi)容 item = soup.find_all("p")[1].string # 使用BeautifulSoup庫的標(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庫解析網(wǎng)頁內(nèi)容 item = soup.find_all("span",class_="passed")[0].string # 使用BeautifulSoup庫的標(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庫解析網(wǎng)頁內(nèi)容 item = soup.find_all("span",class_="skipped")[0].string # 使用BeautifulSoup庫的標(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庫解析網(wǎng)頁內(nèi)容 item = soup.find_all("span",class_="failed")[0].string # 使用BeautifulSoup庫的標(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庫解析網(wǎng)頁內(nèi)容 item = soup.find_all("span",class_="error")[0].string # 使用BeautifulSoup庫的標(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庫解析網(wǎng)頁內(nèi)容 item = soup.find_all("span",class_="xfailed")[0].string # 使用BeautifulSoup庫的標(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庫解析網(wǎng)頁內(nèi)容 item = soup.find_all("span",class_="xpassed")[0].string # 使用BeautifulSoup庫的標(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ā)送測試結(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à)小程序接口自動化測試 \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í)行接口自動化腳本,等待一會然后發(fā)送釘釘消息;
${PYTHON} main.py sleep 100 ${PYTHON} handle_dingding.py
接口自動化發(fā)釘釘群消息還可以再優(yōu)化,比如可以加上斷言失敗的錯誤日志等;
2,監(jiān)控 qa 環(huán)境錯誤日志
這里貼上周游大佬的一篇博客:http://www.dbjr.com.cn/article/250972.htm
此處發(fā)送的 qq 郵件,消息查看不方便,且不好共享,可以優(yōu)化為發(fā)釘釘群消息,然后將開發(fā)也拉到群里,提高效率;
3,jira 上有釘釘機(jī)器人插件,可以每天發(fā)送消息 @ 某某開發(fā) 還有 N 個待處理 bug,@ 某某測試 還有 N 個待驗(yàn)證 bug,以及監(jiān)控看板指標(biāo)達(dá)到閾值報(bào)警等;
以上就是python實(shí)現(xiàn)釘釘機(jī)器人自動打卡天天下早班的詳細(xì)內(nèi)容,更多關(guān)于python釘釘機(jī)器人打卡的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
基于tensorflow指定GPU運(yùn)行及GPU資源分配的幾種方式小結(jié)
今天小編就為大家分享一篇基于tensorflow指定GPU運(yùn)行及GPU資源分配的幾種方式小結(jié),具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-02-02python基于物品協(xié)同過濾算法實(shí)現(xiàn)代碼
這篇文章主要為大家詳細(xì)介紹了python基于物品協(xié)同過濾算法實(shí)現(xiàn)代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-05-05Django定制Admin頁面詳細(xì)實(shí)例(展示頁面和編輯頁面)
django自帶的admin因?yàn)楣δ芎蜆邮奖容^簡陋,常常需要再次定制,下面這篇文章主要給大家介紹了關(guān)于Django定制Admin頁面(展示頁面和編輯頁面)的相關(guān)資料,需要的朋友可以參考下2023-06-06Pytorch 如何實(shí)現(xiàn)LSTM時(shí)間序列預(yù)測
本文主要基于Pytorch深度學(xué)習(xí)框架,實(shí)現(xiàn)LSTM神經(jīng)網(wǎng)絡(luò)模型,用于時(shí)間序列的預(yù)測2021-05-05