Get the App
SLTechnology News&Howtos  ›  Database  › 

Python calls http interface, writes data to mysql database and downloads recording file.

Shulou Source: shulou.com Published: 2022-06-01 15:26:31 09月19日 Update

Writing a script completes a total of three things: first, python calls the http interface, second, writes the called data to the mysql database, and third, python calls the wsdl interface to get the recording file. Import timeimport jsonimport pprintimport MySQLdbimport urllibimport osimport urllib2 # call report interface with import suds # recording pageNum = range (1PM1000) for an in pageNum: url = "http://x.x.x.x:xx/agentProxy/getCallDetail?RN=118117&callType=1&entId=xxxxx&pwd=61712&startTime=20170517000000&endTime=20170517235959&pageNum=" + str (a) req = urllib2.Request (url) res_data = urllib2.urlopen (req) res = res_data.read () data = json.loads (res) Data1 = data [0] data2 = data1 ["callDetailArray"] data4 = data1 ["retCode"] data5 = data1 ["retMsg"] data6 = data1 ["nextPageNum"] data7 = data1 ["RN"] data8 = data1 ["entId"] if len (data1 ['callDetailArray']) = 0: break # print "return code:" Data4, "success:", data5, "next Page:", data6, "RN:", data7, "Enterprise number:", data8, "Total number of entries on this page:" Len (data1 ['callDetailArray']) data9 = len (data1 [' callDetailArray']) l = range (len (data1 ['callDetailArray'])) for i in l: data3 = (data2 [I]) data10 = int (data3 [' sessionId']) data11 = hex (data10) data12 = data11 [2:] data13 = data12 [:-1] data14 = str (data3 ['resourceId']) Data15 = time.strftime ("% Y-%m-%d% X" Time.localtime () url = "http://x.x.x.x:xx/dcmsWebservice/webservice/QueryRecord?wsdl" client=suds.client.Client (url) res = client.service ['QueryRecord'] .queryRecordAddr (" xxxxx ", data14,data14,data13) record= str (res) print record db = MySQLdb.connect (" x.x.x.x "," ucds "," ucds "," report_detail " Charset = "utf8") cursor = db.cursor () sql = "insert into outbound (record_url,sessionId_16,sessionId,resourceId,resourceName,resourceDN,skillId,remoteUrl,localUrl,startTime,endTime, alertDuration,talkDuration,acwDuration,ivrDuration,joinDuration,endType,insertTime) values ("% s ","% s " "% s", "% s") ""\% (record,data13,data3 ['sessionId'], data3 [' resourceId'], data3 ['resourceName'], data3 [' resourceDN'], data3 ['skillId'], data3 [' remoteUrl'], data3 ['localUrl'], data3 [' startTime'], data3 ['endTime'], data3 [' alertDuration'] Data3 ['talkDuration'], data3 [' acwDuration'], data3 ['ivrDuration'], data3 [' joinDuration'], data3 ['endType'], data15) cursor.execute (sql) db.commit () cursor.close () db.close () path=r'E:\ record\ xxxxxxx' if record = = str ('-5'): print "returns-5 No recording file "else: wav = record.split ('/') wav1 = wav [8] dest_dir=os.path.join (path,wav1) urllib.urlretrieve (record,dest_dir) print", (Amur1) * 100-int (data9), "data"

Tags: Interface data file database success code enterprise report script x.x.x.x synchronization Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker MySQL Linux MariaDB Xiaomi