12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- import json
- import time
- import os
- from Utils.Hik_iSecure import Hik_iSecure
- from Utils.Hik_Cloud import Hik_Cloud
- import datetime
- def datetime_now():
- datetimenow = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
- return datetimenow
- # with open("config.json") as f:
- # f_data = json.load(f)
- # host = f_data["host"]
- # appKey = f_data["appKey"]
- # appSecret = f_data["appSecret"]
- # hik_host = f_data["hik_host"]
- # hik_client_id = f_data["hik_client_id"]
- # hik_client_secret = f_data["hik_client_secret"]
- # groupId = f_data["groupId"]
- # sleeptime = f_data["sleeptime"]
- host = os.getenv("host")
- appKey = os.getenv("appKey")
- appSecret = os.getenv("appSecret")
- hik_host = os.getenv("hik_host")
- hik_client_id = os.getenv("hik_client_id")
- hik_client_secret = os.getenv("hik_client_secret")
- groupId = os.getenv("groupId")
- sleeptime = os.getenv("sleeptime")
- while True:
- HikiSecure = Hik_iSecure(host, appKey, appSecret)
- HikCloud = Hik_Cloud(hik_host,hik_client_id,hik_client_secret)
- #获取海康安防系统人员列表
- person_lists = HikiSecure.get_personlist()
- print("%s,获取海康安防平台人员信息成功"%datetime_now())
- #
- # #获取海康云眸人员列表
- hik_person_list = HikCloud.hik_getuserlist()
- #查询需要同步的人员
- diff_value = set(person_lists)-set(hik_person_list)
- if diff_value:
- print("%s,需同步人员%s个" % (datetime_now(), len(diff_value)))
- for employee in diff_value:
- employeeNo = employee
- personName = person_lists[employeeNo][0]
- faceImageBase64 = person_lists[employeeNo][1]
- #往海康云眸添加人员
- print(employeeNo,personName)
- HikCloud.hik_adduser(employeeNo,personName,faceImageBase64)
- #获取海康安防系统人员卡片信息
- cards = HikiSecure.get_card(diff_value)
- print("%s,获取海康安防平台卡片信息成功"%datetime_now())
- cards_only = []
- for i in cards:
- if i not in cards_only:
- cards_only.append(i)
- print(cards_only)
- #往海康云眸添加卡片
- HikCloud.hik_addcard(cards_only)
- # #海康云眸权限组绑定人员
- HikCloud.hik_permissiongroupspersons(groupId,list(diff_value))
- else:
- print("%s 没有需要同步的人员信息"%datetime_now())
- time.sleep(int(sleeptime))
|