前言:
???釘釘有個開發平臺,通過API可以開發自己企業內部應用,釘釘開發文檔順序寫的有點亂,花了挺長時間才看懂,我寫了一個python腳本來獲取考勤記錄,當然能做的不止這些,可以刪除公司成員,修改部門,瞎發通知等等。。。(這是上路的新手,大神忽略。)
?
一、準備?
釘釘API地址:?https://open-doc.dingtalk.com/docs/doc.htm?spm=0.0.0.0.L9JL3j&treeId=367&articleId=107520&docType=1
看 企業自建應用開發流程和企業簡易開發 教程,需要獲取 釘釘管理員權限 ,可問公司組織管理員。
二、python腳本
1.安裝python
官網了解下: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).先調用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).根據API獲取到打卡詳情(釘釘有人數限制,此處已做處理)
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).之后你就可以拿數據存入數據庫了(注意處理返回system的數據)
def get_value(userid_in, access):
l = []
if len(userid_in)>50:
users = []
start = 0
end = 49
while end
?
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

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