# -*- coding : utf-8 -*- import re import os import tqdm import json import glob import datetime import pymysql import requests import threadpool from openpyxl import Workbook, load_workbook def recognition(conversation, customer_id, workspace_id, company_id, session_id, agent_id, create_time, end_time, answer_time, transfer_time, answer_end_time, talk_time, wav_path, voice_type, ip, file_name=''): current_date = datetime.datetime.now().strftime('%Y-%m-%d') if not file_name: file_name = current_date wb = Workbook() ws = wb.active sign_num = 0 content_list = list() '''result = check_data(customer_id, create_time) if result: customer_id = result''' try: if agent_id: ws.append([customer_id, wav_path, create_time, agent_id]) else: ws.append([customer_id, wav_path, session_id]) except Exception: ws.append([customer_id, wav_path]) content_list.append([customer_id, wav_path]) if workspace_id == "341": f = open("./baoxian_line/asr_output/{}.txt".format(file_name), "a") elif workspace_id in ("74743", "935709"): f = open("./360_line/asr_output/{}.txt".format(file_name), "a") elif workspace_id == '307079': f = open("./ws_line/asr_output/{}.txt".format(file_name), "a") elif workspace_id == '545632': f = open("./duxiaoman_line/asr_output/{}.txt".format(file_name), "a") else: f = open("./jintiao_line/asr_output/{}.txt".format(file_name), "a") s = '{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}\n' for i, c in enumerate(conversation): content, type, start_time, end_time = c if answer_time: start_time = int(start_time) # start_time = datetime.datetime.strptime(start_time.split('.')[0], "%M:%S").second start_time = datetime.timedelta(seconds=int(start_time)) if transfer_time: start_time = datetime.datetime.strptime(transfer_time, "%Y-%m-%d %H:%M:%S") + start_time else: start_time = datetime.datetime.strptime(answer_time, "%Y-%m-%d %H:%M:%S") + start_time start_time = start_time.strftime("%Y-%m-%d %H:%M:%S") end_time = int(end_time) # end_time = datetime.datetime.strptime(end_time.split('.')[0], "%M:%S").second end_time = datetime.timedelta(seconds=int(end_time)) if transfer_time: end_time = datetime.datetime.strptime(transfer_time, "%Y-%m-%d %H:%M:%S") + end_time else: end_time = datetime.datetime.strptime(answer_time, "%Y-%m-%d %H:%M:%S") + end_time # end_time = datetime.datetime.strptime(call_start_time, "%Y-%m-%d %H:%M:%S") + end_time end_time = end_time.strftime("%Y-%m-%d %H:%M:%S") if type == 1: if workspace_id: # print( customer_id, content, 1, workspace_id, company_id, create_time, end_time, answer_time, answer_end_time, talk_time, voice_type ) # cursor.execute(sql.format( # customer_id, content, 1, workspace_id, company_id, start_time, end_time, answer_time, # answer_end_time, talk_time, voice_type # )) f.write(s.format(customer_id, content, 1, workspace_id, company_id, start_time, end_time, answer_time,answer_end_time, talk_time, voice_type)) ws.append([customer_id, '1_' + content]) content_list.append([customer_id, '1_' + content]) else: if workspace_id: # print(customer_id, content, 2, workspace_id, company_id, create_time, end_time, answer_time, answer_end_time, talk_time, voice_type) # cursor.execute(sql.format( # customer_id, content, 2, workspace_id, company_id, start_time, end_time, answer_time, # answer_end_time, talk_time, voice_type # )) f.write(s.format(customer_id, content, 2, workspace_id, company_id, start_time, end_time, answer_time,answer_end_time, talk_time, voice_type)) ws.append([customer_id, '2_' + content]) content_list.append([customer_id, '2_' + content]) if workspace_id: f.close() # connection.commit() # connection.close() if not os.path.exists('./{}_data_dir/'.format(ip)): os.mkdir('./{}_data_dir/'.format(ip)) date = '{}-{}-{}'.format(datetime.datetime.now().year, datetime.datetime.now().month, datetime.datetime.now().day) if glob.glob('./{}_data_dir/*.xlsx'.format(ip)) and not glob.glob('./{}_data_dir/*.xlsx'.format(ip))[-1].split('/')[ -1].startswith(date): for file_path in glob.glob('./{}_data_dir/*.xlsx'.format(ip)): os.remove(file_path) wb.save('./{}_data_dir/'.format(ip) + '{}_{}_{}.xlsx'.format(date, customer_id, sign_num)) return sign_num, content_list if __name__ == '__main__': # linshi_sex_false() current_date = datetime.datetime.now().strftime('%Y-%m-%d') print(type(current_date))