| 
					
				 | 
			
			
				@@ -1,159 +0,0 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-from hub import methods, Global 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import threading 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import time 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-class SoundColumns(object): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    """音柱循环检查""" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    mdb = Global.get_mongodb_client() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    api = Global.get_audio_client() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    @classmethod 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    def get_mp3_name_dict(cls): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        mp3_name_dict = dict() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        """ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        FaceType: 人脸类型表 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        FaceType.name: 类型名称 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        FaceType.mp3_name: 音频名称 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        """ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        for item in Global.mdb.get_all('FaceType'): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            uuid = str(item.get('_id')) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            mp3_name_dict[uuid] = item.get('mp3_name') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        return mp3_name_dict 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    @classmethod 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    def get_column_service_url_and_sn(cls): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        """ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        获取音柱信息 todo 建议增加ip校验 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        """ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        unique_dict = {'name': 'AudioConfig'} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        item = cls.mdb.get_one('GlobalVariable', unique_dict) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        data = item.get('args', {}) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        audio_sn = data.get('audio_sn') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        audio_url = f"http://{data.get('audio_ipv4')}:{data.get('audio_port')}" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        audio_vol = data.get('audio_vol') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        return audio_url, audio_sn, audio_vol 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    @classmethod 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    def get_host_ip(cls): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        """ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        获取本机ip 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        """ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        unique_dict = {'name': 'HostIpConfig'} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        item = cls.mdb.get_one('GlobalVariable', unique_dict) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        data = item.get('args', {}) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        host_ip = data.get('ipv4') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        # --- check --- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if not host_ip: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            ssh = Global.SSHClient('172.18.0.1', 22, 'server', 'server') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            out = ssh.run_command("ifconfig") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            for row in out.split('\n\n'): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                if not row.startswith('eth0'):  # eth0 enp0s3 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    continue 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                for one in row.split('\n'): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    one = one.strip() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    if one[:4] != 'inet': 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        continue 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    if one[:5] == 'inet6': 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        continue 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    one = [i for i in one.split(' ') if i] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    ipv4, netmask = one[1], one[3] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    host_ip = ipv4 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        return host_ip 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    @classmethod 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    def check_loop(cls): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        # --- define --- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        last_send_id = str() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        while True: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            # --- check --- 检查是否配置音柱 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            # while True: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            #     unique_dict = {'name': 'AudioConfig'} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            #     item = cls.mdb.get_one('GlobalVariable', unique_dict) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            #     data = item.get('args', {}) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            #     audio_ipv4 = data.get('audio_ipv4') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            #     if audio_ipv4: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            #         break 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            #     else: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            #         time.sleep(60) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            try: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                # --- get send_data --- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                send_data = Global.rdb.get_one(key='send_data') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                # --- check --- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                if not send_data: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    continue 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                # --- check --- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                send_id = send_data.get('send_id') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                if not send_id: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    continue 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                # --- check --- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                if send_id == last_send_id: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    continue 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                # --- check --- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                """ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                send_list = [ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        base_face_uuid: 底库人脸id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        snap_face_image: 抓拍人脸 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        base_face_image_path: 底库人脸路径 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        face_similarity: 相似度 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                ] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                """ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                send_list = send_data.get('send_list') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                if send_list is None or len(send_list) == 0: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    continue 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                # --- debug --- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                # methods.debug_log(f"SoundColumns", f"m-122: run at {methods.now_string()} " 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                #                                    f"| send count is {len(send_list)} ") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                # --- update --- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                last_send_id = send_id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                # --- call --- todo 建议界面上添加个开关,是否启用音响 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                """增加音柱配置写活""" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                audio_url, audio_sn, audio_vol = cls.get_column_service_url_and_sn() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                cls.api.api_service_url = audio_url 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                # cls.api.sn = audio_sn 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                cls.api.vol = audio_vol 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                host_ip = cls.get_host_ip() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                cls.api.file_service_url = f'http://{host_ip}:9900' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                methods.debug_log(f"SoundColumns", f"m-96: file_service_url -> {cls.api.file_service_url}") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                for data in send_list: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    result_type = data.get('result_type') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    # result = cls.api.call_audio_make_sound_v3(result_type) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    result = cls.api.call_audio_make_sound_v4(result_type) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    methods.debug_log(f"SoundColumns", f"m-131: result is {result} | run at {methods.now_string()} |" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                                                       f"send count is {len(send_list)}") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            except Exception as exception: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                methods.debug_log('SoundColumns', f"m-153: exception | {exception}") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                methods.debug_log('SoundColumns', f"m-153: wait 10 minutes try again!") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                time.sleep(600) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                continue 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    @classmethod 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    def run_background(cls, is_back_run=True): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        """""" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        p1 = threading.Thread(target=cls.check_loop) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        p1.start() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-if __name__ == '__main__': 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    SoundColumns.run_background() 
			 |