def __init__(self,**kwargs): super().__init__() self.iprice = Cprice() self.iurls = Curls() self.sperator = '--' self.logger = kwargs.get('logger') self.alert_msg = ''
def insert_url(): iurls = Curls() url = v.get() if url == "": tk.messagebox.showinfo('提示', '不能为空') else: iurls.insert_urls(url, 1) tk.messagebox.showinfo('提示', '导入成功')
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)
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.insert_urls(urls[i], 1) tk.messagebox.showinfo('提示', '导入成功') bulk_win.destroy()
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 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 True: # 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 __init__(self,**kwargs): super().__init__() self.iurls = Curls()
def get_urls(self): iurls = Curls() urls = [] for inst in iurls.query(setting=1): urls.append(inst.url) return urls