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()
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
from db_orm import DealInfo, RegionInfo, SaleInfo, DBSession from sqlalchemy import and_, or_ import csv import os import time import config session = DBSession() def show_sale_info(): query = session.query(SaleInfo.xiaoqu, SaleInfo.total_price, SaleInfo.unit_price, SaleInfo.district,SaleInfo.region, SaleInfo.build_area, SaleInfo.house_area, SaleInfo.room, SaleInfo.orientations, SaleInfo.guapai_time, SaleInfo.url, RegionInfo). \ filter(and_(SaleInfo.region == RegionInfo.region, SaleInfo.district == RegionInfo.district, SaleInfo.house_usage == '普通住宅', RegionInfo.is_too_far == 0, SaleInfo.total_price >= '650', SaleInfo.total_price <= '850', SaleInfo.is_expire == 0)). \ filter(or_(SaleInfo.district == '朝阳', SaleInfo.district == '海淀', SaleInfo.district == '丰台')).\ order_by(SaleInfo.district).order_by(SaleInfo.region).order_by(SaleInfo.xiaoqu) l_r = query.all() l_t_r = [(x.xiaoqu, x.total_price, x.unit_price, x.district, x.region, x.build_area, x.house_area, x.room, x.orientations, x.guapai_time, x.url) for x in l_r] with open(os.path.join( config.PROJ_PATH, 'result/house_info_{}.csv'.format( time.strftime("%Y-%b-%d_%H%M%S"))),
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