日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

釘釘API考勤打卡記錄獲取并存入數(shù)據(jù)庫(python)

系統(tǒng) 3254 0

前言:


???釘釘有個開發(fā)平臺,通過API可以開發(fā)自己企業(yè)內部應用,釘釘開發(fā)文檔順序寫的有點亂,花了挺長時間才看懂,我寫了一個python腳本來獲取考勤記錄,當然能做的不止這些,可以刪除公司成員,修改部門,瞎發(fā)通知等等。。。(這是上路的新手,大神忽略。)
?

一、準備?

釘釘API地址:?https://open-doc.dingtalk.com/docs/doc.htm?spm=0.0.0.0.L9JL3j&treeId=367&articleId=107520&docType=1

企業(yè)自建應用開發(fā)流程和企業(yè)簡易開發(fā) 教程,需要獲取 釘釘管理員權限 ,可問公司組織管理員。

二、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).先調用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
              
            
          

?


更多文章、技術交流、商務合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯(lián)系: 360901061

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

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!?。?/p>

發(fā)表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 金沙县| 伊金霍洛旗| 明星| 张掖市| 云安县| 武乡县| 海宁市| 通渭县| 格尔木市| 曲麻莱县| 庐江县| 资源县| 泌阳县| 黄大仙区| 阿图什市| 班玛县| 大埔县| 治多县| 监利县| 泽库县| 巨野县| 吉木萨尔县| 冕宁县| 佛学| 陆河县| 常德市| 清涧县| 手游| 基隆市| 达尔| 深州市| 西吉县| 辉南县| 镇沅| 赞皇县| 晴隆县| 民县| 历史| 鹤峰县| 山东| 安阳县|