main.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import json
  2. import time
  3. import os
  4. from Utils.Hik_iSecure import Hik_iSecure
  5. from Utils.Hik_Cloud import Hik_Cloud
  6. import datetime
  7. def datetime_now():
  8. datetimenow = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
  9. return datetimenow
  10. # with open("config.json") as f:
  11. # f_data = json.load(f)
  12. # host = f_data["host"]
  13. # appKey = f_data["appKey"]
  14. # appSecret = f_data["appSecret"]
  15. # hik_host = f_data["hik_host"]
  16. # hik_client_id = f_data["hik_client_id"]
  17. # hik_client_secret = f_data["hik_client_secret"]
  18. # groupId = f_data["groupId"]
  19. # sleeptime = f_data["sleeptime"]
  20. host = os.getenv("host")
  21. appKey = os.getenv("appKey")
  22. appSecret = os.getenv("appSecret")
  23. hik_host = os.getenv("hik_host")
  24. hik_client_id = os.getenv("hik_client_id")
  25. hik_client_secret = os.getenv("hik_client_secret")
  26. groupId = os.getenv("groupId")
  27. sleeptime = os.getenv("sleeptime")
  28. while True:
  29. HikiSecure = Hik_iSecure(host, appKey, appSecret)
  30. HikCloud = Hik_Cloud(hik_host,hik_client_id,hik_client_secret)
  31. #获取海康安防系统人员列表
  32. person_lists = HikiSecure.get_personlist()
  33. print("%s,获取海康安防平台人员信息成功"%datetime_now())
  34. #
  35. # #获取海康云眸人员列表
  36. hik_person_list = HikCloud.hik_getuserlist()
  37. #查询需要同步的人员
  38. diff_value = set(person_lists)-set(hik_person_list)
  39. if diff_value:
  40. print("%s,需同步人员%s个" % (datetime_now(), len(diff_value)))
  41. for employee in diff_value:
  42. employeeNo = employee
  43. personName = person_lists[employeeNo][0]
  44. faceImageBase64 = person_lists[employeeNo][1]
  45. #往海康云眸添加人员
  46. print(employeeNo,personName)
  47. HikCloud.hik_adduser(employeeNo,personName,faceImageBase64)
  48. #获取海康安防系统人员卡片信息
  49. cards = HikiSecure.get_card(diff_value)
  50. print("%s,获取海康安防平台卡片信息成功"%datetime_now())
  51. cards_only = []
  52. for i in cards:
  53. if i not in cards_only:
  54. cards_only.append(i)
  55. print(cards_only)
  56. #往海康云眸添加卡片
  57. HikCloud.hik_addcard(cards_only)
  58. # #海康云眸权限组绑定人员
  59. HikCloud.hik_permissiongroupspersons(groupId,list(diff_value))
  60. else:
  61. print("%s 没有需要同步的人员信息"%datetime_now())
  62. time.sleep(int(sleeptime))