Exemplo n.º 1
0
    def getRealTimeToJiayou(self,company):
        '''
            调用该函数去该供应商进行实时获取
        '''
        m_result = []
        
        if company is None:
            companys = settings.GET_PRICE_FROM_ONLINE
        else:
            if company in settings.GET_PRICE_FROM_ONLINE:
                companys = [company]
            else:
                companys = []
        
        id = 100000000        
        for company in companys:
            result = {'partno':self.partno,'qty':self.qty,'online':True,'allow_stock':True,'slug':'','company':company}
            
            supplier = settings.SUPPLIER_DICT[str(company)]
            result.update({'supplier':supplier})
            
            if supplier == 'roch-ti':
                supplier = 'roch'

            spider = SupplierSpider(supplier)
            #获取库存数量和价格列表。
            results = spider.get_info(self.partno,True)
            
            if results:
                for t_result in results:
                    t_result.update(result)
                    t_result.update({'id':id})
                    t_result = self._get_data(t_result)
                    m_result.append(t_result)
                    id += 1
        
        return m_result        
Exemplo n.º 2
0
    def test_supplier(self):
        """
            返回该供应商该型号的查找结果
            #下面供应商的数据都可以从数据库里直接获取
            GET_PRICE_FROM_DATABASE = ('0','2','3','4','6','7','8','9','14',)
            
            #下面供应商数据暂不能直接从数据库中获取
            NOT_GET_PRICE_FROM_DATABASE = ('1',)
            
            #暂时只支持下面6个供应商的官网实时获取
            GET_PRICE_FROM_ONLINE = ('1','2','3','4','9','14',)
            
        """
        # 如果需要去官网去实时获取数据,则支持下面供应商
        if self.online:
            from_online = settings.GET_PRICE_FROM_ONLINE
        else:
            from_online = settings.NOT_GET_PRICE_FROM_DATABASE

        from_database = True

        if str(self.company) in from_online:  # 是否从网上获取
            ##TODO 非常重要。李东修改了这里 2011-10-20
            # 实时获取数据时,如果是roch-ti的就去roch的网上去找
            if self.supplier == "roch-ti":
                supplier = "roch"
            else:
                supplier = self.supplier

            spider = SupplierSpider(supplier)
            # 获取库存数量和价格列表。
            results = spider.get_info(self.partno, self.is_mouser_login)
            #####由邢嵩岩在2013.09.23日修改#####
            """修改get_info调用时候第二个参数,来源为icgoo的请求全部都不查询折扣假"""
            results = spider.get_info(self.partno, False)
            #################################
            """
            #因为mouser的实时获取不再登陆,所以不能获取到折扣价,这里折扣价从库里读取
            if self.supplier == 'mouser' and not self.is_mouser_login:
                obj = Product.objects.get(slug=self.slug)
                if len(results) == 0:
                    pass
                elif len(results) == 1:
                    try:
                        results[0]['msp_new'] = pickle.loads(str(obj.yourcost))
                    except Exception,e:
                        results[0]['msp_new'] = []
                else:
                    for one in results:
                        if str(one['supp_partno']) == str(obj.supplier_partno):
                            try:
                                one['msp_new'] = pickle.loads(str(obj.yourcost))
                            except Exception,e:
                                one['msp_new'] = []  
                            break
            """
            # 下面这一段先注释掉,如果网上没有获取信息,还不如不显示,数据库里的信息肯定是不准的.
            """
            if not results:#未实时从网上获取信息,改为数据库获取   
                from_database = True
                if supplier == 'mouser':
                    from_database = False
            else:
                from_database = False
            """

            # add this by 2012-05-15 mouser用数据库的数量,网上的阶梯价格
            """
            if supplier == 'mouser':
                obj = Product.objects.get(slug=self.slug)
                try:
                    results[0]['stock'] = int(obj.items_in_stock)
                except Exception,e:
                    pass
            """
            from_database = False

        if from_database:
            results = []
            try:
                obj = Product.objects.get(slug=self.slug)

                # 现阶段主要为roch服务,reel为True起订是以250起,且价格段都要是50的倍数
                self.reel = obj.reel
                if self.reel == 1:
                    self.reel = True
                else:
                    self.reel = False

                # temp_dict = {'msp_new':[]}
                temp_dict = {}
                ##xf edit this by 2011 08 25
                # if supplier == 'hot' and obj.mfr.strip().lower() == 'ramtron':
                # temp_dict['stock'] = u'0  可立即发货<br />在订货物: 2500<br />工厂交货期: 16 周'
                # else:
                # temp_dict['stock'] = obj.items_in_stock
                try:
                    temp_dict["stock"] = int(obj.items_in_stock)
                except Exception, e:
                    temp_dict["stock"] = 0
                # end edit
                try:
                    temp_dict["min"] = int(obj.min)
                except Exception, e:
                    temp_dict["min"] = 1
                try:
                    if obj.package:
                        temp_dict["packaging"] = str(obj.package)
                    else:
                        temp_dict["packaging"] = u""
                except Exception, e:
                    temp_dict["packaging"] = u""