UserId.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # -*- coding: utf-8 -*-
  2. import dingtalk.api
  3. import json
  4. from Utils.AccessToken import access_token
  5. def userid(accesstoken):
  6. req = dingtalk.api.OapiSmartworkHrmEmployeeQueryonjobRequest(
  7. "https://oapi.dingtalk.com/topapi/smartwork/hrm/employee/queryonjob")
  8. req.status_list = "2,3,5,-1"
  9. req.offset = 0
  10. req.size = 50
  11. userid_list = []
  12. try:
  13. resp= req.getResponse(accesstoken)
  14. data_list = resp["result"]["data_list"]
  15. userid_list.extend(data_list)
  16. if resp["result"]["next_cursor"] is not None:
  17. while True:
  18. resp = req.getResponse(accesstoken)
  19. data_list = resp["result"]["data_list"]
  20. userid_list.extend(data_list)
  21. if "next_cursor" in resp["result"]:
  22. req.offset = resp["result"]["next_cursor"]
  23. else:
  24. break
  25. except Exception as e:
  26. print(e)
  27. print("钉钉用户%s个"%len(userid_list))
  28. return userid_list
  29. if __name__ == '__main__':
  30. with open("../config.json") as f:
  31. data = json.load(f)
  32. appkey = data["appkey"]
  33. appsecret = data["appsecret"]
  34. client_id = data["client_id"]
  35. client_secret = data["client_secret"]
  36. groupId = data["groupId"]
  37. sleeptime = data["sleeptime"]
  38. userid(access_token(appkey,appsecret))