def __init__(self, keyword): ''' 港元对美元的汇率 访问这个网址可以查询 http://www.baidu.com/s?ie=utf-8&bs=港元兑美元&f=8&rsv_bp=1&rsv_spt=3&wd=港元兑美元&inputT=0 ''' self.huilv_hk_us = 0.1288#最后更新时间 2013年 04月 26日 星期五 11:14:53 CST self.keyword = keyword SOAPpy.Config.buildWithNamespacePrefix = 0 SOAPpy.Config.debug = 0 #0禁止调试信息 SOAPpy.Config.dumpHeadersOut = 0 #调试信息 SOAPpy.Config.dumpSOAPOut = 0 SOAPpy.Config.dumpSOAPIn = 0 self.customerid = 24067 #self.locale = 'en_CN' self.locale = 'en_HK' self.server_url="https://hk.element14.com/pffind/services/SearchService" #soapaction="https://hk.element14.com/pffind/services/SearchService", timestamp = get_timestamp() operate_name = 'searchByKeyword' signature = get_signature(operate_name,timestamp) data = {'v1:userInfo':{"v1:signature": signature, "v1:timestamp": timestamp, "v1:locale": self.locale, }, 'v1:accountInfo':{"v1:customerId": self.customerid,} } hd = headerType(data = data) self.server=SOAPProxy(self.server_url, namespace="http://pf.com/soa/services/v1", \ noroot=1, header=hd) self.server.soapaction="https://hk.element14.com/pffind/services/SearchService"
def searchByPremierFarnellPartNumber(self, keyword): """根据厂商型号关键字搜索结果 keyword: 型号关键字 返回:data 一个products结果集 """ ''' <?xml version="1.0" encoding="UTF-8"?> <soapenv:Envelope soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:v1="http://pf.com/soa/services/v1" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/1999/XMLSchema" > <soapenv:Header> <v1:userInfo> <v1:locale>en_HK</v1:locale> <v1:timestamp>2011-10-18T09:15:44.198</v1:timestamp> <v1:signature>qk3ZOxzi30Qv/Aj/wXTkgH7fLBc=</v1:signature> </v1:userInfo> <v1:accountInfo> <v1:customerId>24067</v1:customerId> </v1:accountInfo> </soapenv:Header> <soapenv:Body> <v1:premierFarnellPartNumber> <v1:Sku>LTC2630AHSC6</v1:Sku> </v1:premierFarnellPartNumber> </soapenv:Body> </soapenv:Envelope> ''' timestamp = get_timestamp() operate_name = 'searchByPremierFarnellPartNumber' signature = get_signature(operate_name,timestamp) data = {'v1:userInfo':{"v1:signature": signature, "v1:timestamp": timestamp, "v1:locale": self.locale, }, 'v1:accountInfo':{"v1:customerId": self.customerid,} } hd = headerType(data = data) self.server=SOAPProxy(self.server_url, namespace="http://pf.com/soa/services/v1", \ noroot=1, header=hd) self.server.soapaction="https://hk.element14.com/pffind/services/SearchService" searchdata = {'v1:premierFarnellPartNumbers':{'v1:Sku': keyword, }, } data = self.server.searchByManufacturerPartNumber(**searchdata) data = data.products if not isinstance(data, list): data = [data] return data