Exemplo n.º 1
0
 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
Exemplo n.º 2
0
 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()
Exemplo n.º 3
0
 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()
Exemplo n.º 4
0
 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
Exemplo n.º 5
0
 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
Exemplo n.º 6
0
    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