12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- import os.path
- import time
- import requests
- import json
- import datetime
- import random
- from Utils.HikGetUserlist import hik_getuserlist
- def datetime_now():
- datetimenow = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
- return datetimenow
- def hik_face_fail(hik_accesstoken):
- headers = {"content-type": "application/json"}
- data = {
- "pageNo": 1,
- "pageSize": 100,
- "groupId": "d9619b66e6e44615b505e7676c0fbb02"
- # "deviceSerial": "K45055572"
- }
- response = requests.post(
- url="https://api2.hik-cloud.com/api/v1/open/accessControl/allots/actions/searchStatus?access_token=%s" % hik_accesstoken,
- headers=headers,
- data=json.dumps(data)
- )
- return response.json()
- def get_user_face(hik_accesstoken,employeeNo):
- response = requests.get(
- url="https://api2.hik-cloud.com/api/v1/open/basic/persons/get?access_token=%s&employeeNo=%s" %(hik_accesstoken, employeeNo)
- )
- name = response.json()["data"]["personName"]
- face = response.json()["data"]["faceUrl"]
- return name,face
- if __name__ == '__main__':
- d = "data"
- face_fail = hik_face_fail("997b7086-9bba-46dd-a8f9-03c055ec586c")
- face_fail = face_fail["data"]["rows"]
- employeeNos = []
- for i in face_fail:
- employeeNo = i["employeeNo"]
- if employeeNo not in employeeNos:
- employeeNos.append(employeeNo)
- print(employeeNos)
- for em in employeeNos:
- name,face_url = get_user_face("997b7086-9bba-46dd-a8f9-03c055ec586c",em)
- if face_url is not None:
- print(em,name,face_url)
- time.sleep(2)
- headers = {
- "Connection": "keep-alive",
- "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"
- }
- r = requests.get(face_url,headers=headers)
- path = d + "/"+em +"-"+ name +".jpg"
- with open(path,"wb") as f:
- f.write(r.content)
|