face_fail.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import os.path
  2. import time
  3. import requests
  4. import json
  5. import datetime
  6. import random
  7. from Utils.HikGetUserlist import hik_getuserlist
  8. def datetime_now():
  9. datetimenow = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
  10. return datetimenow
  11. def hik_face_fail(hik_accesstoken):
  12. headers = {"content-type": "application/json"}
  13. data = {
  14. "pageNo": 1,
  15. "pageSize": 100,
  16. "groupId": "d9619b66e6e44615b505e7676c0fbb02"
  17. # "deviceSerial": "K45055572"
  18. }
  19. response = requests.post(
  20. url="https://api2.hik-cloud.com/api/v1/open/accessControl/allots/actions/searchStatus?access_token=%s" % hik_accesstoken,
  21. headers=headers,
  22. data=json.dumps(data)
  23. )
  24. return response.json()
  25. def get_user_face(hik_accesstoken,employeeNo):
  26. response = requests.get(
  27. url="https://api2.hik-cloud.com/api/v1/open/basic/persons/get?access_token=%s&employeeNo=%s" %(hik_accesstoken, employeeNo)
  28. )
  29. name = response.json()["data"]["personName"]
  30. face = response.json()["data"]["faceUrl"]
  31. return name,face
  32. if __name__ == '__main__':
  33. d = "data"
  34. face_fail = hik_face_fail("997b7086-9bba-46dd-a8f9-03c055ec586c")
  35. face_fail = face_fail["data"]["rows"]
  36. employeeNos = []
  37. for i in face_fail:
  38. employeeNo = i["employeeNo"]
  39. if employeeNo not in employeeNos:
  40. employeeNos.append(employeeNo)
  41. print(employeeNos)
  42. for em in employeeNos:
  43. name,face_url = get_user_face("997b7086-9bba-46dd-a8f9-03c055ec586c",em)
  44. if face_url is not None:
  45. print(em,name,face_url)
  46. time.sleep(2)
  47. headers = {
  48. "Connection": "keep-alive",
  49. "User-Agent": "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Mobile Safari/537.36"
  50. }
  51. r = requests.get(face_url,headers=headers)
  52. path = d + "/"+em +"-"+ name +".jpg"
  53. with open(path,"wb") as f:
  54. f.write(r.content)