Parking_space_Python/Violation_stable_0429/PTZ/main.py
2024-04-29 13:42:00 +08:00

81 lines
2.8 KiB
Python

import threading
import datetime
from Class.Violation_class import Violation
from Class.Pass_class import Pass
from Class.Car_num_check_class import Car_num_check
import requests
import urllib3
import time
from requests.structures import CaseInsensitiveDict
from Class.API_class import Parking_spaces_API, Start_API
# API
api = Start_API()
class start_run(threading.Thread):
def __init__(self, parking_space_list, parent=None):
super().__init__(parent)
self.parking_space_list = parking_space_list
self.api = Start_API()
def run(self):
print('thread {} '.format(threading.current_thread().name)) # 查看線程
self.violation_list = []
self.pass_list = []
self.car_num_check_list = []
for parking_space_name in self.parking_space_list:
cam_data = self.api.get_one_cam_data(parking_space_name)
for i1 in range(0, len(cam_data)):
#  判斷進出
if cam_data['mode'][i1] == "pass":
webcam_data = {}
webcam_data['parking_spaces_name'] = cam_data['parking_spaces_name'][i1]
webcam_data['url'] = cam_data['url'][i1]
webcam_data['mode'] = cam_data['mode'][i1]
self.pass_list.append(Pass(webcam_data))
#  判斷違規
if cam_data['mode'][i1] == "violation":
webcam_data = {}
webcam_data['parking_spaces_name'] = cam_data['parking_spaces_name'][i1]
webcam_data['url'] = cam_data['url'][i1]
webcam_data['mode'] = cam_data['mode'][i1]
self.violation_list.append(Violation(webcam_data))
#  數量確認
if cam_data['mode'][i1] == "car_num_check":
webcam_data = {}
webcam_data['parking_spaces_name'] = cam_data['parking_spaces_name'][i1]
webcam_data['url'] = cam_data['url'][i1]
webcam_data['mode'] = cam_data['mode'][i1]
self.car_num_check_list.append(Car_num_check(webcam_data))
# for i in range(0, len(self.pass_list)):
# self.pass_list[i].start()
# for i in range(0, len(self.car_num_check_list)):
# self.car_num_check_list[i].start()
for i in range(0,len(self.violation_list)):
self.violation_list[i].start()
if __name__ == '__main__':
parking_space_list = []
all_cam_data = api.get_all_cam_data()
for i in range(0, len(all_cam_data)):
# print(data)
try:
parking_space_list.index(all_cam_data['parking_spaces_name'][i])
except:
parking_space_list.append(all_cam_data['parking_spaces_name'][i])
program = start_run(parking_space_list)
program.run()