# -*- coding : utf-8 -*- import os import json import glob import time import shutil import pymysql import datetime import requests import traceback import threading import tornado.web import tornado.ioloop import tornado.options import tornado.httpserver from urllib import parse from tornado.web import RequestHandler from openpyxl import Workbook, load_workbook # from 金融线 import rule # from 金融线 import qiwei_rule import rule import qiwei_rule from utillib import PlatformBase # 人人对话存储type:0:甲方纯人,1:自平台纯人,2:自平台人机实转,3:自平台人机非实转 port = 9506 wav_dir = './wav_dir' wechat_robot_dict ={ '一级': ['https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=4f031558-97de-4106-88a2-2f2a2a332ed4', '4f031558-97de-4106-88a2-2f2a2a332ed4'], '二级': ['https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=3b7de4ac-717d-496b-a849-c5f92c050a20', '3b7de4ac-717d-496b-a849-c5f92c050a20'], '三级': ['https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=f4f046b6-e489-48b1-8751-393a47d580ac', 'f4f046b6-e489-48b1-8751-393a47d580ac'], '四级': ['https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=424f14ee-e084-43f6-89fa-03fc708bbc66', '424f14ee-e084-43f6-89fa-03fc708bbc66'], } company_dict = { '2114': '菁卡', '2117': '菁卡', '2130': '水滴', '2132': '金条', '2137': '京东加微', '2140': '企业主贷', '2143': '京小贷', '2144': '金条', '2141': '还呗', '2160': '京东借钱', '2165': '还呗FS', '2170': '黑牛' } wechat_robot = 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=7ef36edc-654e-45f8-aed5-3ff3df2ed272' class Robot_self(PlatformBase): def get_content_from_session(self, session_id, workspace_id): url = "http://47.92.230.239:8630/report/getDetailedRecord?sessionId={}&workSpaceId={}".format(session_id, workspace_id) resposne = requests.get(url) result = json.loads(resposne.text) # result = httpservice.http_get(url, timeout=5) # print( result ) return result["result"] def send_wechat_warning(self, customer_id, ip): headers = {'Content-Type': 'application/json'} title = '京东金条(质检)' text = {'content': '{}\n{}\n{}\n音频格式错误'.format(title, ip, customer_id)} webhook = 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=cfc9a7ec-fae4-4802-9844-caae493e5ab4' data = { 'msgtype': 'text', 'text': text } data = json.dumps(data) response = requests.request('POST', webhook, headers=headers, data=data, timeout=1) content = response.text def send_back(self, ip, customer_id, sign): sign = '不合格' if sign else '合格' response = requests.get( 'http://39.98.54.147:8005/writeBack?ip={}&customerId={}&checkResult={}'.format(ip, customer_id, sign)) def record_all(self, ip, name, company, group, call_id, customer_id, workspace_id, company_id, session_id, wav_path, start_time, answer_time, transfer_time, end_time, call_duration, robot_sign, sign, final_level, robot_user, robot_worker, robot_false_sign, human_false_sign, content_human, content_robot): date_day = '{}-{}-{}'.format(datetime.datetime.now().year, datetime.datetime.now().month, datetime.datetime.now().day) date = '{}-{}-{} {}:{}:{}'.format(datetime.datetime.now().year, datetime.datetime.now().month, datetime.datetime.now().day, datetime.datetime.now().hour, datetime.datetime.now().minute, datetime.datetime.now().second, ) if glob.glob('./{}_data_dir/*.xlsx'.format(ip)) and date_day not in glob.glob('./{}_data_dir/*.xlsx'.format(ip))[0]: for file_path in glob.glob('./{}_data_dir/*.xlsx'.format(ip)): os.remove(file_path) if robot_sign and sign: file_name = '{}_严重客诉总结_通话录音_{}.xlsx'.format(company_dict[company_id], date) file_name_all = '{}_{}_严重客诉总结.xlsx'.format(company_dict[company_id], date_day) if not os.path.exists('./{}_data_dir/{}'.format(ip, file_name)): fp = open('./{}_data_dir/{}'.format(ip, file_name), 'w') fp.write('话单ID\t客服ID\t京东用户名\t违规质检结果\t一级分类\t二级分类\t质检项\t错误规则\t命中语句\t' '客诉质检结果\t质检项\t错误规则\t命中语句\t是否有责\t音频地址\t坐席姓名\t末次接通时间\t' '监听日期\t振铃开始时间\t电话开始时间\t电话结束时间\t通话时长\t是否接通\t外拨职场\t外拨小组\n') else: fp = open('./{}_data_dir/{}'.format(ip, file_name), 'a') elif robot_sign and not sign: # file_name = '{}_一般客诉总结_通话录音_{}.xlsx'.format(company_dict[company_id], date) file_name_all = '{}_{}_一般客诉总结.xlsx'.format(company_dict[company_id], date_day) elif not robot_sign and sign: # file_name = '{}_轻微客诉总结_通话录音_{}.xlsx'.format(company_dict[company_id], date) file_name_all = '{}_{}_轻微客诉总结.xlsx'.format(company_dict[company_id], date_day) else: # file_name = '{}_无客诉总结_通话录音_{}.xlsx'.format(company_dict[company_id], date) file_name_all = '{}_{}_无客诉总结.xlsx'.format(company_dict[company_id], date_day) if not os.path.exists('./{}_data_dir/'.format(ip)): os.mkdir('./{}_data_dir/'.format(ip)) if not os.path.exists('./{}_data_dir/{}'.format(ip, file_name_all)): fp_all = open('./{}_data_dir/{}'.format(ip, file_name_all), 'w') fp_all.write('话单ID\t客服ID\t京东用户名\t违规质检结果\t一级分类\t二级分类\t质检项\t错误规则\t命中语句\t' '客诉质检结果\t质检项\t错误规则\t命中语句\t是否有责\t音频地址\t坐席姓名\t末次接通时间\t' '监听日期\t振铃开始时间\t电话开始时间\t电话结束时间\t通话时长\t是否接通\t外拨职场\t外拨小组\n') else: fp_all = open('./{}_data_dir/{}'.format(ip, file_name_all), 'a') if robot_worker: input_list = [ call_id, customer_id, '', '不合格' if sign else '合格', robot_worker[0][0], robot_worker[0][1], robot_worker[0][2], robot_worker[0][3], '', '不合格' if robot_sign else '合格', final_level if robot_sign else '', '_'.join(robot_user), '', '', wav_path, name, start_time, date, '', answer_time, end_time, call_duration, '是', company, group] else: input_list = [ call_id, customer_id, '', '不合格' if sign else '合格', '', '', '', '', '', '不合格' if robot_sign else '合格', final_level if robot_sign else '', '_'.join(robot_user), '', '', wav_path, name, start_time, date, '', answer_time, end_time, call_duration, '是', company, group] if robot_false_sign: input_list[9] = '获取信息错误' input_list[10] = '' if human_false_sign: input_list[3] = '获取信息错误' ''' if not content_robot: input_list[9] = '获取信息为空' input_list[10] = '' if not content_human: input_list[3] = '获取信息为空' ''' fp_all.write( '\t'.join(input_list) + '\n' ) fp_all.close() if robot_sign and sign: fp.write( '\t'.join(input_list) + '\n' ) fp.close() send_wechat_file('一级', './{}_data_dir/{}'.format(ip, file_name)) elif robot_sign and not sign: pass # send_wechat_file('二级', './{}_data_dir/{}'.format(ip, file_name_all)) elif not robot_sign and sign: pass # send_wechat_file('三级', './{}_data_dir/{}'.format(ip, file_name_all)) # wechat_robot def task(self, ip, name, company, group, call_id, customer_id, workspace_id, company_id, session_id, wav_path, start_time, answer_time, transfer_time, end_time, call_duration): robot_false_sign = False human_false_sign = False content_human = '' content_robot = '' if session_id: try: content_robot = self.get_content_from_session(session_id, workspace_id) except Exception: content_robot = '' robot_false_sign = True traceback.print_exc() time = 0 if call_duration: try: self.download_to_wav(wav_path, customer_id, ip) self.get_human_port_from(call_duration) chat_record, time, channel, sign = self.get_content(customer_id) if not sign: return 0 content_human = self.optimize_record(chat_record) except Exception: content_human = '' human_false_sign = True traceback.print_exc() if content_human: # mysql存储 # for content in content_human: # print( content ) pass robot_sign, sign, final_level, robot_user, robot_worker = rule.recognition( content_human, content_robot, ip, name, start_time, answer_time, end_time, call_id, customer_id, session_id, workspace_id, company_id, wav_path, time ) self.record_all(ip, name, company, group, call_id, customer_id, workspace_id, company_id, session_id, wav_path, start_time, answer_time, transfer_time, end_time, call_duration, robot_sign, sign, final_level, robot_user, robot_worker, robot_false_sign, human_false_sign, content_human, content_robot) def get(self): ip = self.get_argument('IP', '') name = self.get_argument('displayName', '') company = self.get_argument('displayCompany', '') group = self.get_argument('displayGroup', '') call_id = self.get_argument('callId', '') customer_id = self.get_argument('customerId', '') workspace_id = self.get_argument('workspaceId', '222') company_id = self.get_argument('companyId', '') session_id = self.get_argument('sessionId', '') start_time = self.get_argument('startTime', '') answer_time = self.get_argument('answerTime', '') transfer_time = self.get_argument('transferTime', '') end_time = self.get_argument('endTime', '') call_duration = self.get_argument('callDuration', '') wav_path = self.get_argument('wavPath', '') # access_key = 'AWSAccessKeyId=' + self.get_argument('AWSAccessKeyId', '') if self.get_argument('AWSAccessKeyId', '') else '' expires = 'Expires=' + self.get_argument('Expires', '') if self.get_argument('Expires', '') else '' signature = 'Signature=' + self.get_argument('Signature', '') if self.get_argument('Signature', '') else '' if company_id not in ['2114', '2117', '2140', '2141', '2143', '2144', '2160', '2165']: self.write('success') return if expires and signature: wav_path = '&'.join([wav_path, expires, parse.quote(signature)]) self.task(ip, name, company, group, call_id, customer_id, workspace_id, company_id, session_id, wav_path, start_time, answer_time, transfer_time, end_time, call_duration) '''p = threading.Thread(target=self.task, args=(ip, name, company, group, call_id, customer_id, workspace_id, company_id, session_id, wav_path, start_time, answer_time, transfer_time, end_time, call_duration)) p.start()''' self.write('success') class Human_company(PlatformBase): def optimize_record(self, chat_record): content_list = list() if chat_record: for c in chat_record: if c.content not in ['', ',', '正在呼叫请稍候,', '用户已挂机', '对对对对对对对,', '对对对对对对,', '对对对对对,', '对对对对,', '多多多多多多多,', '多多多多多多,', '多多多多多,', '多多多多,', '多多多', ]: # c.content = c.content.replace(',', '') content_list.append([c.content, 0 if c.role == 'staff' else 1]) return content_list def get_content_from_session(self, session_id, workspace_id): url = "http://47.92.230.239:8630/report/getDetailedRecord?sessionId={}&workSpaceId={}".format(session_id, workspace_id) resposne = requests.get(url) result = json.loads(resposne.text) # result = httpservice.http_get(url, timeout=5) return result["result"] def send_wechat_warning(self, customer_id, ip): headers = {'Content-Type': 'application/json'} title = '京东金条(质检)' text = {'content': '{}\n{}\n{}\n音频格式错误'.format(title, ip, customer_id)} webhook = 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=cfc9a7ec-fae4-4802-9844-caae493e5ab4' data = { 'msgtype': 'text', 'text': text } data = json.dumps(data) response = requests.request('POST', webhook, headers=headers, data=data, timeout=1) content = response.text def send_back(self, ip, customer_id, sign): sign = '不合格' if sign else '合格' response = requests.get( 'http://39.98.54.147:8005/writeBack?ip={}&customerId={}&checkResult={}'.format(ip, customer_id, sign)) def record_all(self, ip, name, company, group, call_id, customer_id, workspace_id, company_id, session_id, wav_path, start_time, answer_time, transfer_time, end_time, call_duration, robot_sign, sign, final_level, robot_user, robot_worker, robot_false_sign, human_false_sign, content_human, content_robot): date_day = '{}-{}-{}'.format(datetime.datetime.now().year, datetime.datetime.now().month, datetime.datetime.now().day) date = '{}-{}-{} {}:{}:{}'.format(datetime.datetime.now().year, datetime.datetime.now().month, datetime.datetime.now().day, datetime.datetime.now().hour, datetime.datetime.now().minute, datetime.datetime.now().second, ) if glob.glob('./{}_data_dir/*.xlsx'.format(ip)) and date_day not in glob.glob('./{}_data_dir/*.xlsx'.format(ip))[0]: for file_path in glob.glob('./{}_data_dir/*.xlsx'.format(ip)): os.remove(file_path) if robot_sign and sign: file_name = '{}_甲方_严重客诉总结_通话录音_{}.xlsx'.format(company_dict[company_id], date) file_name_all = '{}_甲方_{}_严重客诉总结.xlsx'.format(company_dict[company_id], date_day) if not os.path.exists('./{}_data_dir/{}'.format(ip, file_name)): fp = open('./{}_data_dir/{}'.format(ip, file_name), 'w') fp.write('话单ID\t客服ID\t京东用户名\t违规质检结果\t一级分类\t二级分类\t质检项\t错误规则\t命中语句\t' '客诉质检结果\t质检项\t错误规则\t命中语句\t是否有责\t音频地址\t坐席姓名\t末次接通时间\t' '监听日期\t振铃开始时间\t电话开始时间\t电话结束时间\t通话时长\t是否接通\t外拨职场\t外拨小组\n') else: fp = open('./{}_data_dir/{}'.format(ip, file_name), 'a') elif robot_sign and not sign: # file_name = '{}_一般客诉总结_通话录音_{}.xlsx'.format(company_dict[company_id], date) file_name_all = '{}_甲方_{}_一般客诉总结.xlsx'.format(company_dict[company_id], date_day) elif not robot_sign and sign: # file_name = '{}_轻微客诉总结_通话录音_{}.xlsx'.format(company_dict[company_id], date) file_name_all = '{}_甲方_{}_轻微客诉总结.xlsx'.format(company_dict[company_id], date_day) else: # file_name = '{}_无客诉总结_通话录音_{}.xlsx'.format(company_dict[company_id], date) file_name_all = '{}_甲方_{}_无客诉总结.xlsx'.format(company_dict[company_id], date_day) if not os.path.exists('./{}_data_dir/'.format(ip)): os.mkdir('./{}_data_dir/'.format(ip)) if not os.path.exists('./{}_data_dir/{}'.format(ip, file_name_all)): fp_all = open('./{}_data_dir/{}'.format(ip, file_name_all), 'w') fp_all.write('话单ID\t客服ID\t京东用户名\t违规质检结果\t一级分类\t二级分类\t质检项\t错误规则\t命中语句\t' '客诉质检结果\t质检项\t错误规则\t命中语句\t是否有责\t音频地址\t坐席姓名\t末次接通时间\t' '监听日期\t振铃开始时间\t电话开始时间\t电话结束时间\t通话时长\t是否接通\t外拨职场\t外拨小组\n') else: fp_all = open('./{}_data_dir/{}'.format(ip, file_name_all), 'a') if robot_worker: input_list = [call_id, customer_id, '', '不合格' if sign else '合格', robot_worker[0][0], robot_worker[0][1], robot_worker[0][2], robot_worker[0][3], '', '不合格' if robot_sign else '合格', final_level if robot_sign else '', '_'.join(robot_user), '', '', wav_path, name, start_time, date, '', answer_time, end_time, call_duration, '是', company, group] else: input_list = [call_id, customer_id, '', '不合格' if sign else '合格', '', '', '', '', '', '不合格' if robot_sign else '合格', final_level if robot_sign else '', '_'.join(robot_user), '', '', wav_path, name, start_time, date, '', answer_time, end_time, call_duration, '是', company, group] if robot_false_sign: input_list[9] = '获取信息错误' input_list[10] = '' if human_false_sign: input_list[3] = '获取信息错误' ''' if not content_robot: input_list[9] = '获取信息为空' input_list[10] = '' if not content_human: input_list[3] = '获取信息为空' ''' fp_all.write( '\t'.join(input_list) + '\n' ) fp_all.close() '''if robot_sign and sign: fp.write( '\t'.join(input_list) + '\n' ) fp.close() send_wechat_file('一级', './{}_data_dir/{}'.format(ip, file_name)) elif robot_sign and not sign: pass # send_wechat_file('二级', './{}_data_dir/{}'.format(ip, file_name_all)) elif not robot_sign and sign: pass # send_wechat_file('三级', './{}_data_dir/{}'.format(ip, file_name_all)) ''' # wechat_robot def task(self, ip, name, company, group, call_id, customer_id, workspace_id, company_id, session_id, wav_path, start_time, answer_time, transfer_time, end_time, call_duration): robot_false_sign = False human_false_sign = False content_human = '' content_robot = '' if session_id: try: content_robot = self.get_content_from_session(session_id, workspace_id) except Exception: content_robot = '' robot_false_sign = True traceback.print_exc() if call_duration: try: self.download_to_wav(wav_path, customer_id, ip) self.get_human_port_from(call_duration) chat_record, time, channel, sign = self.get_content(customer_id) if not sign: return 0 content_human = self.optimize_record(chat_record) except Exception: content_human = '' human_false_sign = True print(human_false_sign) traceback.print_exc() # print( human_false_sign ) if content_human: # mysql存储 pass robot_sign, sign, final_level, robot_user, robot_worker = rule.recognition( content_human, content_robot, ip, name, start_time, answer_time, end_time, call_id, customer_id, session_id, workspace_id, company_id, wav_path, call_duration ) self.record_all(ip, name, company, group, call_id, customer_id, workspace_id, company_id, session_id, wav_path, start_time, answer_time, transfer_time, end_time, call_duration, robot_sign, sign, final_level, robot_user, robot_worker, robot_false_sign, human_false_sign, content_human, content_robot) def get(self): ip = self.get_argument('IP', '') name = self.get_argument('displayName', '') company = self.get_argument('displayCompany', '') group = self.get_argument('displayGroup', '') call_id = self.get_argument('callId', '') customer_id = self.get_argument('customerId', '') workspace_id = self.get_argument('workspaceId', '222') company_id = self.get_argument('companyId', '') session_id = self.get_argument('sessionId', '') start_time = self.get_argument('startTime', '') answer_time = self.get_argument('answerTime', '') transfer_time = self.get_argument('transferTime', '') end_time = self.get_argument('endTime', '') call_duration = self.get_argument('callDuration', '') wav_path = self.get_argument('wavPath', '') # access_key = 'AWSAccessKeyId=' + self.get_argument('AWSAccessKeyId', '') if self.get_argument('AWSAccessKeyId', '') else '' expires = 'Expires=' + self.get_argument('Expires', '') if self.get_argument('Expires', '') else '' signature = 'Signature=' + self.get_argument('Signature', '') if self.get_argument('Signature', '') else '' if expires and signature: wav_path = '&'.join([wav_path, expires, parse.quote(signature)]) self.task(ip, name, company, group, call_id, customer_id, workspace_id, company_id, session_id, wav_path, start_time, answer_time, transfer_time, end_time, call_duration) '''p = threading.Thread(target=self.task, args=(ip, name, company, group, call_id, customer_id, workspace_id, company_id, session_id, wav_path, start_time, answer_time, transfer_time, end_time, call_duration)) p.start()''' self.write('success') class Qiwei_chat(RequestHandler): def rpa_task(self, customer_id, ip): connection = pymysql.connect(host="39.103.215.119", port=3307, user="workwx_manager_user", passwd="LingXi2021@)@!", db="work-weixin-manager", charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor) cursor = connection.cursor() sql_msg = 'select msg_content, msg_type, msg_time, msg_send, msg_receive, ' \ 'cus_wechat_name, agent_name ' \ 'from chat_record_rpa ' \ 'where customer_id = "{}"; ' cursor.execute(sql_msg.format(customer_id)) results_msg = cursor.fetchall() msg_list = list() for msg in results_msg: msg_type = msg['msg_type'] msg_time = msg['msg_time'] msg_send = msg['msg_send'] msg_receive = msg['msg_receive'] wechat_name = msg['cus_wechat_name'] agent_name = msg['agent_name'] if msg_type == 'text': msg_content = eval(msg['msg_content']) content = msg_content['content'] if msg_send.startswith('JD'): msg_list.append([content, 1, msg_time]) else: msg_list.append([content, 2, msg_time]) qiwei_rule.recognition(msg_list, customer_id, wechat_name, agent_name, 'jintiao', ip) def self_task(self, no_id, ip): connection = pymysql.connect(host="39.103.215.119", port=3307, user="workwx_manager_user", passwd="LingXi2021@)@!", db="work-weixin-manager", charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor) cursor = connection.cursor() sql_msg = 'select msg_content, msg_type, msg_time, sender, username, ' \ 'account_id, contact_id, contact_serial_no ' \ 'from chat_record ' \ 'where contact_serial_no = "{}"; ' cursor.execute(sql_msg.format(no_id)) results_msg = cursor.fetchall() msg_list = list() for msg in results_msg: msg_type = msg['msg_type'] msg_time = msg['msg_time'] msg_send = msg['sender'] username = msg['username'] account_id = msg['account_id'] contact_id = msg['contact_id'] contact_serial_no = msg['contact_serial_no'] # print( type(msg_type) ) if msg_type == 2001: content = msg['msg_content'] if msg_send == 'agent': msg_list.append([content, 1, msg_time]) else: msg_list.append([content, 2, msg_time]) qiwei_rule.recognition(msg_list, no_id, contact_serial_no, username, 'jintiao', ip) def task(self, id, ip): if ip == '京东rpa': self.rpa_task(id, ip) elif ip == '京东自有': self.self_task(id, ip) def get(self): '''id = self.get_argument('id', '') add_time = self.get_argument('addTime', '') wechat_name = self.get_argument('cusWechatName', '') agent_name = self.get_argument('agentName', '') update_time = self.get_argument('updateTime', '') relation_type = self.get_argument('relaationTypeCn', '') company_id = self.get_argument('companyId', '') group_name = self.get_argument('groupName', '') create_time = self.get_argument('createTime', '') msg_receive = self.get_argument('msgRecevice', '') bill_id = self.get_argument('billId', '') customer_id = self.get_argument('customerId', '') action = self.get_argument('action', '') workspace_name = self.get_argument('workspaceName', '') user_wechat_id = self.get_argument('userWechatId', '') agent_wechat_id = self.get_argument('agentWechatId', '') msg_send = self.get_argument('msgSend', '')''' id = self.get_argument('id', '') ip = self.get_argument('ip', '') self.task(id, ip) def post(self): self.get() def send_wechat_file(level, filename): # print(wechat_robot_dict[level][1]) date = '{}:{}'.format(datetime.datetime.now().hour, datetime.datetime.now().minute) if level == '二级' or level == '三级': if date not in ['11:0', '15:0', '18:0', '20:0']: return if level == '四级': if date not in ['21:0']: return upload_url = 'https://qyapi.weixin.qq.com/cgi-bin/webhook/upload_media?key={}&type=file'.format(wechat_robot_dict[level][1]) headers = { 'Content-Length': '220', 'Content-type': 'multipart/form-data', 'Content-Disposition': 'form-data; name="media"; filename="{}"; filelength=6;'.format(filename), # 'Content-Type': 'application/octet-stream', # 'name': 'media', # 'filename': filename, # 'filelength': '6', # 'file': open(filename, 'rb'), } data = { 'file': open(filename, "rb"), } # print(upload_url) response = requests.post(upload_url, files=data) # print(response) # print(response.text) result = json.loads(response.text) media_id = result['media_id'] data ={ 'msgtype': 'file', 'file': { 'media_id': media_id, } } headers = {'Content-Type': 'application/json'} response = requests.post(wechat_robot_dict[level][0], data=json.dumps(data), headers=headers) if filename.endswith('客诉总结.xlsx'): shutil.move(filename, filename.replace('客诉总结.xlsx', '{}客诉总结.xlsx'.format(date))) else: os.remove(filename) def send_wechat_warning(customer_id, ip, text): headers = {'Content-Type': 'application/json'} title = '京东金条(质检)' text = {'content': '{}\n{}\n{}\n{}'.format(title, ip, customer_id, text) } webhook = 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=b517f035-d07a-4131-8f91-20fba7b504ca' data = { 'msgtype': 'text', 'text': text } data = json.dumps(data) response = requests.request('POST', webhook, headers=headers, data=data, timeout=1) content = response.text def check_task(): while True: clock = '{}:{}'.format(datetime.datetime.now().hour, datetime.datetime.now().minute) if clock in ['11:00', '15:00', '18:00', '20:00']: file_paths = glob.glob('./*_data_dir/*_轻微客诉总结.xlsx') for file_path in file_paths: send_wechat_file('三级', file_path) time.sleep(20) class Call_back( RequestHandler ): def task(self, ip, company): date = '{}-{}-{}'.format(datetime.datetime.now().year, datetime.datetime.now().month, datetime.datetime.now().day) xlsx_list = glob.glob('./{}_data_dir/*_*_*.xlsx'.format(ip)) '''xlsx_tuple = list() # 按时长排序 for xlsx_file in xlsx_list: try: xlsx_tuple.append( (xlsx_file, int(xlsx_file.split('_')[-1].split('.')[0])) ) except Exception: pass xlsx_tuple = sorted(xlsx_tuple, key=lambda x:x[-1], reverse=True)''' wb = Workbook() ws = wb.active num_1 = 0 num_2 = 0 ws['A1'] = '话单ID' ws['B1'] = '客户ID' ws['C1'] = '姓名/修正意见' ws['D1'] = '末次接通时间/错误类型' ws['E1'] = '音频地址/错误规则' ws['F1'] = '命中语句/电话号码' ws['G1'] = '录音内容' for xlsx in xlsx_list: if xlsx.split('_')[-1].split('.')[0] in ['1', 'True']: num_1 += 1 else: num_2 += 1 wb_s = load_workbook(xlsx) ws_s = wb_s[wb_s.sheetnames[0]] for row in ws_s.values: # row = row[:list(row).index(None)] ws.append(row) ws.append(['', ]) wb.save('./{}_data_dir/{}_{}_{}_{}_总结.xlsx'.format(ip, date, ip, num_1, num_2)) def get(self): ip = self.get_argument('ip', '') company = self.get_argument('company', '') p = threading.Thread(target=self.task, args=(ip, company)) p.start() self.write('success') if __name__ == '__main__': # send_wechat_file('四级', '../金融线/自平台_data_dir/2021-12-26_无客诉总结.xlsx') tornado.options.parse_command_line() app = tornado.web.Application([ (r'/robot_self', Robot_self), (r'/human_company', Human_company), (r'/qiwei_chat', Qiwei_chat), (r'/call_back', Call_back), # (r'/asr_data', ASR_data) ], static_path=os.path.join(os.path.dirname(__file__), "static"), template_path=os.path.join(os.path.dirname(__file__), "template"), debug=False ) http_server = tornado.httpserver.HTTPServer(app) http_server.listen(port) http_server.start(40) print("starting") tornado.ioloop.IOLoop.current().start() print("starting ... ")