# —*- coding :utf-8 -*- import time import pymysql import datetime import requests def quality_test_jiaoyu(date, company_id, company): url = 'http://localhost:9501/quality_test?customerId={}&displayName={}&wavPath={}&callDuration={}&' \ 'callDate={}&callId={}&ip={}&answerDate={}&transferDate={}&phone={}&company={}' connection = pymysql.connect(host="47.92.76.236", port=13306, user="readonly", passwd="Moxi123#", db="outbound_platform", charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor) cursor = connection.cursor() sql = 'select ocr.dm_session_id, ocr.case_id, ocr.voice_path, ocr.customer_id, ' \ 'ocr.call_start_time, ocr.answer_time, ocr.transfer_time, ocr.total_call_duration, ' \ 'ocr.phone_number, ocr.agent_id ' \ 'from outbound_call_result ocr ' \ 'where ocr.company_id = {} ' \ 'and ocr.call_status = "normalConnection" ' \ 'and ocr.call_start_time > "{} 00:09:00" ' \ 'and ocr.call_start_time < "{} 23:59:59" ' \ 'and ocr.human_answer_duration > 30 ' \ 'and ocr.transfer_time is not null; '.format(company_id, date, date) cursor.execute(sql) results = cursor.fetchall() print( len(results) ) for i, data in enumerate(results): session_id = data['dm_session_id'] case_id = data['case_id'] customer_id = data['customer_id'] voice_path = data['voice_path'] call_duration = data['total_call_duration'] call_start_time = data['call_start_time'] call_answer_time = data['answer_time'] call_transfer_time = data['transfer_time'] phone = data['phone_number'] name = data['agent_id'] response = requests.get(url.format( session_id, name, voice_path, call_duration, call_start_time, case_id, company_id, call_answer_time, call_transfer_time, phone, company)) ''' if company == 'jiaoyu': response = requests.get(url.format( session_id, name, voice_path, call_start_time, case_id, company_id, call_answer_time, call_transfer_time, phone, company)) elif company == 'jingka': response = requests.get(url.format( customer_id, name, voice_path, call_start_time, case_id, company_id, call_answer_time, call_transfer_time, phone, company)) ''' time.sleep(10) if i > 2000: break if __name__ == '__main__': date = datetime.date.today() - datetime.timedelta(days=4) print( date ) quality_test_jiaoyu(date, 2149, 'fandeng')