예제 #1
0
def quick():
    ## CODE
    import SOAPpy
    test = 42

    server=SOAPProxy(url, namespace="http://pf.com/soa/services/v1", noroot=1, \
                        soapaction="https://hk.element14.com/pffind/services/SearchService")
    server = server._sa ("urn:soapinterop")

    hd = server.Header()
    hd.InteropTestHeader ='This should fault, as you don\'t understand the header.'
    hd._setMustUnderstand ('InteropTestHeader', 0)
    hd._setActor ('InteropTestHeader','http://schemas.xmlsoap.org/soap/actor/next')
    server = server._hd (hd)
예제 #2
0
    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"
예제 #3
0
    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
예제 #4
0
class GetDataFromElement(object):
    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 searchByKeyword(self, offset=0, numberOfResults=5):
        """根据型号关键字搜索结果
        keyword: 型号关键字
        offset: 返回结果集开始索引
        numberOfResults: 最多显示条数
        返回:data 一个products结果集
        """
        '''
        <soapenv:Header>
            <v1:userInfo>
                <v1:signature>lSZqdtXpws6VODO1tCeMToqsPZQ=</v1:signature>
                <v1:timestamp>2011-10-13T09:30:18.198</v1:timestamp> 
                <v1:locale>en_HK</v1:locale> 
            </v1:userInfo>
            <v1:accountInfo>
                <!--You have a CHOICE of the next 3 items at this level-->
                <v1:customerId>24067</v1:customerId> 
                <v1:contractId></v1:contractId>
                <v1:billingAccountNo></v1:billingAccountNo>
                </v1:accountInfo>
        </soapenv:Header>
        <body>
             <v1:keywordParameter>
                  <v1:keyword>avr</v1:keyword>
                  <v1:offset>0</v1:offset>
                  <v1:numberOfResults>25</v1:numberOfResults>
             ...
             </v1:keywordParameter>
        </body>
        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"
        '''
        searchdata  = {'v1:keywordParameter':{'v1:keyword': self.keyword,
                        'v1:offset': offset,
                        'v1:numberOfResults': numberOfResults,
                        },
                      }
        data = self.server.searchByKeyword(**searchdata)
        if data == '0':
             return []
        data = data.products
        if not isinstance(data, list):
            data = [data]
        return data

    def getdatainfo(self):
        """
        返回list_finall的三种格式:
            1. [None,{'html':html}] 
            2. ['similar',{'similar partno':[[sp,sp_url],...],'html':html},...] 
            3. ['exact',{'mp':mp,'price':price,...},...]
            4. ['no_result',{'html':html}] 
        每个字典元素的的键字存在于列表useful_keys_mouser_tt = ['Manufacturer','Description','Lifecycle',
                'Stock', 'On Order', 'Factory Lead-Time',
                'Minimum','Multiples','Price','Reel','More']
        """
        data = self.searchByKeyword()
        list_finall = []
        if not data:
            list_finall = ['no_result', {}]
        else:
            list_finall.append('exact')
            for d in data:
                d_dict = self.getdatainfo_one(d)
                partno = d_dict['Manufacturer Part']
                if self.keyword == partno:
                    #continue
                    list_finall.append(d_dict)

        if len(list_finall) == 1:
            list_finall = ['similar']
            for d in data:
                d_dict = self.getdatainfo_one(d)
                list_finall.append(d_dict)
        return list_finall

    def getdatainfo_one(self, d):
        d_dict = {}
        ''' 调用keys_mouser_tt变量的内容 避免手动写死 2012年 12月 31日 星期一 13:30:56 CST '''
        d_dict[keys_mouser_tt[14][1]] = '%s / package' % d.packSize#添加包装个数 edit by daimingming on 2013年 01月 24日 星期四 17:44:17 CST

        #d_dict['Manufacturer Part'] = d.translatedManufacturerPartNumber
        d_dict[keys_mouser_tt[1][1]] = d.translatedManufacturerPartNumber
        
        #d_dict['Manufacturer'] = d.brandName
        d_dict[keys_mouser_tt[2][1]] = d.brandName
        
        #d_dict['Stock'] = d.inv
        d_dict[keys_mouser_tt[5][1]] = d.inv
        
        ''' Stock_info 显示效果较乱 并且不被调用 所以可不返回 2012年 12月 31日 星期一 13:34:14 CST '''
        #d_dict['Stock_info'] = d.stock.regionalBreakdown
        
        #d_dict['Minimum'] = d.translatedMinimumOrderQuality
        d_dict[keys_mouser_tt[8][1]] = d.translatedMinimumOrderQuality
        
        #d_dict['Reel'] = d.reeling
        d_dict[keys_mouser_tt[11][1]] = d.reeling
        
        #d_dict['Rohs'] = d.rohsStatusCode
        d_dict[keys_mouser_tt[24][1]] = d.rohsStatusCode

        #element14_ordercode  xf edit this by 2013 05 27
        d_dict[keys_mouser_tt[18][1]]   = d.sku
        #d_dict[keys_mouser_tt[32][1]]   = d.sku

        #element14_countryOfOrigin xf edit this by 2013 05 27
        d_dict[keys_mouser_tt[34][1]]   = d.countryOfOrigin
        #d_dict[keys_mouser_tt[33][1]]   = d.countryOfOrigin

        price_str = ''
        try:
            prices = d.prices
            try:
                price_str = '%s:$%s' % (prices['from'], float(prices['cost']) * self.huilv_hk_us)
            except:
                for one in prices:
                    price_str += '%s:$%s|||' % (one['from'], float(one['cost']) * self.huilv_hk_us)

                if price_str and price_str[-3:] == '|||':
                    price_str = price_str[:-3]
        except:
            pass
        #d_dict['Price'] = price_str
        d_dict[keys_mouser_tt[10][1]] = price_str
        return d_dict

    def parse_msg(self, data):
        """分析searchByKeyword返回的数据"""
        attr_list = [u'attributes', u'brandId', u'brandName', u'comingSoon', u'commodityClassCode', u'countryOfOrigin', u'datasheets', u'discountReason', u'displayName', u'id', u'image', u'inv', u'isAwaitingRelease', u'isSpecialOrder', u'packSize', u'prices', u'productStatus', u'publishingModule', u'reeling', u'releaseStatusCode', u'rohsStatusCode', u'sku', u'stock', u'translatedManufacturerPartNumber', u'translatedMinimumOrderQuality', u'translatedPrimaryCatalogPage', u'unitOfMeasure', u'vatHandlingCode', u'vendorId', u'vendorName', u'related']
        for d in data:
            print '=' * 80 
            for one in attr_list:
                try:
                    exec('value = d.%s' % one)
                    print '%s ---- %s' % (one, value)
                except:
                    pass

            print '===== prices (from ---- to: cost) ====='
            try:
                prices = d.prices
                try:
                    print '%s ---- %s: %s' % (prices['from'], prices['to'], prices['cost'])
                except:
                    for one in prices:
                        print '%s ---- %s: %s' % (one['from'], one['to'], one['cost'])
            except:
                pass
            try:

                print '===== stock ====='
                stock = d.stock
                stock_attr = [u'breakdown', u'leastLeadTime', u'level', u'nominatedWarehouseDetails', u'regionalBreakdown', u'shipsFromMultipleWarehouses', u'status']
                for s_one in stock_attr:
                    exec('value = stock.%s' % s_one)
                    print '%s ---- %s' % (s_one, value)
            except:
                pass

            try:
                print '===== attributes ====='
                attributes = d.attributes
                for one in attributes:
                    print '%s ---- %s' % (one.attributeLabel, one.attributeValue)
            except:
                pass

    def searchByManufacturerPartNumber(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-18T08:56:40.198</v1:timestamp>
        <v1:signature>UUS1qJ4i1eljxe4aPiIqKhTZXMI=</v1:signature>
        </v1:userInfo>
        <v1:accountInfo>
        <v1:customerId>24067</v1:customerId>
        </v1:accountInfo>
        </soapenv:Header>
        <soapenv:Body>
        <v1:manufacturerPartNumber>
        <v1:ManufacturerPartNumber>LTC2630AHSC6</v1:ManufacturerPartNumber>
        </v1:manufacturerPartNumber>
        </soapenv:Body>
        </soapenv:Envelope>
        '''
        timestamp = get_timestamp()
        operate_name = 'searchByManufacturerPartNumber'
        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:manufacturerPartNumber':{'v1:ManufacturerPartNumber': keyword, }, }
        data = self.server.searchByManufacturerPartNumber(**searchdata)
        data = data.products
        if not isinstance(data, list):
            data = [data]
        return data

    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