def persist(self, list_r): try: session = DBSession() is_stop = None for i in list_r: if i.is_expire is 0: l_stored_data = session.query(SaleInfo).filter( SaleInfo.code == i.code).all() if l_stored_data: i.price_change = str( float(i.total_price) - float(l_stored_data[0].total_price)) session.merge(i) else: session.query(SaleInfo).filter(SaleInfo.code == i.code).\ update({SaleInfo.is_expire: 1}) session.commit() log.info_logger.info( 'persist {} items of data, and is_stop = {}'.format( len(list_r), True if is_stop else False)) except Exception as e: session.rollback() log.info_logger.error('Exception:{}'.format(e)) log.error_logger.error(e, exc_info=True) finally: session.close() return True if is_stop else False
def persist(self, list_r): try: session = DBSession() for i in list_r: session.merge(i) session.commit() print('persist {} items of region data'.format(len(list_r))) except Exception as e: session.roolback() print(e) finally: session.close() return False
def persist(self, list_r): try: session = DBSession() for i in list_r: session.merge(i) session.commit() log.info_logger.info('persist {} items of region data'.format( len(list_r))) except Exception as e: session.roolback() log.info_logger.error('Exception:{}'.format(e)) log.error_logger.error('Url:{}'.format(url)) log.info_logger.error(e, exc_info=True) finally: session.close() return False
def persist(self, list_r): try: session = DBSession() is_stop = None #is_stop = session.query(DealInfo).filter(DealInfo.code == list_r[0].code).one_or_none() for i in list_r: session.merge(i) session.commit() print('persist {} items of deal data, and is_stop = {}'.format( len(list_r), True if is_stop else False)) except Exception as e: session.roolback() print(e) finally: session.close() return True if is_stop else False