189 8069 5689

python调用http接口,数据写入mysql数据库并下载录音文件-创新互联

写个脚本一共完成了三件事: 第一,python调用http接口, 第二,把调用到的数据写入mysql数据库, 第三,python调用wsdl接口,获取录音文件, import time import json import pprint import MySQLdb import urllib import os import urllib2 #调报表接口用 import suds #调录音用 pageNum = range(1,1000) for a 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 "返回代码:",data4,"是否成功:",data5,"下一页:",data6,"RN:",data7,"企业编号:",data8,"本页总条数:",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","%s","%s","%s","%s","%s","%s","%s","%s","%s","%s","%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 "返回-5,无录音文件"         else:             wav = record.split('/')             wav1 = wav[8]             dest_dir=os.path.join(path,wav1)             urllib.urlretrieve(record,dest_dir) print "本次共同步:",(a-1)*100-int(data9),"条数据"

成都创新互联主营芙蓉网站建设的网络公司,主营网站建设方案,app软件开发公司,芙蓉h5微信平台小程序开发搭建,芙蓉网站营销推广欢迎芙蓉等地区企业咨询

另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


分享标题:python调用http接口,数据写入mysql数据库并下载录音文件-创新互联
文章转载:http://cdxtjz.cn/article/cohgij.html

其他资讯