JobId.py 859 B

1234567891011121314151617181920212223242526272829
  1. # -*- coding: utf-8 -*-
  2. import dingtalk.api
  3. def jobid(userid_list,accesstoken):
  4. req = dingtalk.api.OapiSmartworkHrmEmployeeListRequest(
  5. "https://oapi.dingtalk.com/topapi/smartwork/hrm/employee/list")
  6. user_dict = {}
  7. for i in range(0,len(userid_list),50):
  8. userranges = userid_list[i:i+50]
  9. req.userid_list=",".join(userranges)
  10. try:
  11. resp= req.getResponse(accesstoken)["result"]
  12. for user in resp:
  13. # userid = user["userid"]
  14. field_list = user["field_list"]
  15. JobNumber = ""
  16. UserName = ""
  17. for field in field_list:
  18. # print(field)
  19. if field["field_code"] == "sys00-name":
  20. UserName = field["value"]
  21. if field["field_code"] == "sys00-jobNumber":
  22. JobNumber = field["value"]
  23. JobNumber = JobNumber.replace(" ","")
  24. user_dict[JobNumber] = UserName
  25. except Exception as e:
  26. print(e)
  27. return user_dict