前言:
???釘釘有個(gè)開發(fā)平臺(tái),通過API可以開發(fā)自己企業(yè)內(nèi)部應(yīng)用,釘釘開發(fā)文檔順序?qū)懙挠悬c(diǎn)亂,花了挺長時(shí)間才看懂,我寫了一個(gè)python腳本來獲取考勤記錄,當(dāng)然能做的不止這些,可以刪除公司成員,修改部門,瞎發(fā)通知等等。。。(這是上路的新手,大神忽略。)
?
一、準(zhǔn)備?
釘釘API地址:?https://open-doc.dingtalk.com/docs/doc.htm?spm=0.0.0.0.L9JL3j&treeId=367&articleId=107520&docType=1
看 企業(yè)自建應(yīng)用開發(fā)流程和企業(yè)簡易開發(fā) 教程,需要獲取 釘釘管理員權(quán)限 ,可問公司組織管理員。
二、python腳本
1.安裝python
官網(wǎng)了解下:https://www.python.org/downloads/
了解完下載下
下載完安裝下(路徑注意不要中文)。
2.安裝pymysql庫
CDM命令pip install PyMySQL。如圖:
:\Users\Administrator> pip install PyMySQL
Collecting PyMySQL
Downloading PyMySQL-0.7.11-py2.py3-none-any.whl (78kB)
51% |████████████████▋ |
40kB 109kB/s eta 0:0 64% |████████████████████▊
| 51kB 112kB/s eta 77% |█████████████████████████ | 61kB 135kB/s 90% |█████████████████████████████
| 71kB 152 100% |████████████████████████████████| 81kB 163kB/s
Installing collected packages: PyMySQL
Successfully installed PyMySQL-0.7.11
C:\Users\Administrator>
3.腳本編寫
1).先調(diào)用API獲取到token
def getaccseetoken():
request = dingtalk.api.OapiGettokenRequest("https://oapi.dingtalk.com/gettoken")
request.corpid = "你的cropid"
request.corpsecret = "你的corpsecret "
f = request.getResponse()
access_token = f['access_token']
return access_token
2).有了token后通過API獲取用戶UserId
def get_userid(access_token):
request = dingtalk.api.OapiAttendanceListscheduleRequest('https://oapi.dingtalk.com/topapi/attendance/listschedule')
request.workDate = str(dt.strftime(dt.now(), '%Y-%m-%d %H:%M:%S'))
f = request.getResponse(access_token)
userid = list(map(lambda x: x["userid"], f['result']['schedules']))
userid = list(set(userid))
return userid
3).根據(jù)API獲取到打卡詳情(釘釘有人數(shù)限制,此處已做處理)
def get_attendence_listrecord(userid, access_token, day):
request = dingtalk.api.OapiAttendanceListRecordRequest('https://oapi.dingtalk.com/attendance/list')
request.workDateFrom = str(dt.now() - day * timedelta(days=1))
request.workDateTo = str(dt.now())
request.userIdList = userid
request.offset = 0
request.limit = 50
f = request.getResponse(access_token)
h = []
h.append(f)
while ('hasMore', True) in f.items():
request.offset = request.offset+request.limit
f = request.getResponse(access_token)
h.append(f)
return h
4).之后你就可以拿數(shù)據(jù)存入數(shù)據(jù)庫了(注意處理返回system的數(shù)據(jù))
def get_value(userid_in, access):
l = []
if len(userid_in)>50:
users = []
start = 0
end = 49
while end
?
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號(hào)聯(lián)系: 360901061
您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對(duì)您有幫助就好】元
