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 clear_table(self): try: session = DBSession() session.query(SaleInfo).filter().update({SaleInfo.is_expire: 1}) session.commit() print('clear done') except Exception as e: session.rollback() print(e) finally: session.close()
def clear_table(self): try: session = DBSession() session.query(SaleInfo).filter().update({SaleInfo.is_expire: 1}) session.commit() log.info_logger.info('clear done') except Exception as e: session.rollback() log.info_logger.error('Exception:{}'.format(e)) log.error_logger.error('Url:{}'.format(url)) log.error_logger.error(e, exc_info=True) finally: session.close()