示例#1
0
 def __init__(self, **kwargs):
     super().__init__()
     self.iprice = Cprice()
     self.iurls = Curls()
     self.sperator = '--'
     self.logger = kwargs.get('logger')
     self.alert_msg = ''
示例#2
0
 def dump_goods(self):
     if self.chooseDict:
         iurls = Curls()
         for k, (goods, url) in self.chooseDict.items():
             iurls.update(f'url={url}',
                          setting=1,
                          goods=goods,
                          origin_time=datetime.datetime.now())
             self.labelList[k % 8].configure(bg=self.bgcolor[k % 8 % 4 % 2])
         self.chooseDict = {}
         self.chooseV.set("已选择:0")
示例#3
0
 def get_detail():
     iurls = Curls()
     urls = self.text.get(1.0, tk.END)
     urls = urls.split('\n')[:-1]
     if urls == ['']:
         tk.messagebox.showinfo('提示', '不能为空')
     else:
         for i in range(len(urls)):
             iurls.update(f'url={urls[i]}', setting=1, goods='')
         self.crawl_goods(urls)
         tk.messagebox.showinfo('提示', '导入成功')
     bulk_win.destroy()
示例#4
0
 def insert_url():
     iurls = Curls()
     url = v.get()
     if url == "":
         tk.messagebox.showinfo('提示', '不能为空')
     else:
         iurls.update(
             f'url={url}',
             setting=1,
         )
         self.crawl_goods(urls=[url])
         tk.messagebox.showinfo('提示', '导入成功')
示例#5
0
class GoodsPipe(Pipeline):
    def __init__(self, **kwargs):
        super().__init__()
        self.iurls = Curls()

    def itemProcess(self, rsp):
        if rsp is not None:
            insert_time = datetime.datetime.now()
            # 存入数据库
            self.iurls.update(f'url={rsp["href"] }',
                              goods=rsp['goods'],
                              origin_time=insert_time)
示例#6
0
 def add_data(self):
     '''加载配置、数据'''
     iurls = Curls()
     self.data = {}
     data = {}
     for i,inst in enumerate(iurls.query()):
         self.goodsId[i] = (inst.id,inst.goods)
         dic = {}
         dic['goods'] = inst.goods
         dic['common_price'] = inst.common_price
         dic['expect_price'] = inst.expect_price
         dic['setting'] = inst.setting
         data[i] = dic
         self.data[i] = dic.copy()
     self.table.model.importDict(data)
示例#7
0
class PricePipe(Pipeline):
    def __init__(self, **kwargs):
        super().__init__()
        self.iprice = Cprice()
        self.iurls = Curls()
        self.sperator = '--'
        self.logger = kwargs.get('logger')
        self.alert_msg = ''

    def itemProcess(self, rsp):
        if rsp is not None:
            skuid = urlsplit(rsp.url)[3].split('=')[1]
            price = float(rsp.json()[0]['p'])  # 单个商品
            href = f'https://item.jd.com/{skuid}.html'
            # 商品id
            inst = self.iurls.query(url=href)[0]
            id = inst.id
            goods = inst.goods if inst.goods is not None else ''
            insert_time = datetime.datetime.now()
            # 存入数据库
            self.iprice.insert(gid=id, price=price, date_time=insert_time)
            # 价格变化
            delta = 0
            price_inst = self.iprice.session.query(Price).\
                filter(Price.gid==id).order_by(Price.id.desc()).first()
            if price_inst is not None:
                delta = price - price_inst.price
            # 提醒
            if delta != 0:  #
                # 无界面
                self.alert_msg += f'{goods}\t:{delta}\n'
                # 有界面
                info = self.sperator.join(['alert', goods, str(delta)])
                if self.logger is not None:  # 界面提醒
                    self.logger.info(info)
            # 输出日志
            if self.logger is not None:
                info = 'logger' + self.sperator + goods + self.sperator + '成功'
                # print(info)
                self.logger.info(info)  # 需要对数据进行格式化
        else:
            if self.logger is not None:
                info = 'logger' + self.sperator + '' + self.sperator + '失败'
                self.logger.info(info)  # 需要对数据进行格式化

    def __del__(self):
        alerter = Alerter()
        alerter.info(self.alert_msg)
示例#8
0
文件: __init__.py 项目: p9s/jd_price
 def get_urls(self):
     iurls = Curls()
     urls = []
     for inst in iurls.query(setting=1):
         urls.append(inst.url)
     return urls
示例#9
0
 def modify(self):
     iurls = Curls()
     for k,vals in self.table.model.data.items():
         if self.data[k] != vals:
             iurls.update(f'id={self.goodsId[k][0]}',**vals)
示例#10
0
 def __init__(self, **kwargs):
     super().__init__()
     self.iurls = Curls()