示例#1
0
    def new_deal_price(self):
        for i in collection_new.find(no_cursor_timeout=True):
            print(collection_new.database.client.address[0])
            if 'fj_flag' in i:
                if i['fj_flag'] == 1:
                    deal_price = Comm(self.new_source)
                    deal_price.city = i['fj_city']
                    deal_price.region = i['fj_region']
                    deal_price.district_name = i['fj_name']
                    deal_price.avg_price = float(i["CJDJ"])
                    # deal_price.total_price = float(i["CJJE"]) * 10000
                    deal_price.trade_date = i['CJRQ']
                    deal_price.area = float(i['JZMJ'])
                    deal_price.room_num = i['SH']

                    deal_price.total_price = float(i['JZMJ']) * float(
                        i["CJDJ"])
                    try:
                        room = re.search('(.)室', i['FX'], re.S | re.M).group(1)
                        deal_price.room = check_room(room)
                    except Exception as e:
                        print('找不到室,FX={}, e={}'.format(i['FX'], e))
                    try:
                        hall = re.search('(.)厅', i['FX'], re.S | re.M).group(1)
                        deal_price.hall = check_room(hall)
                    except Exception as e:
                        print('找不到厅,FX={}, e={}'.format(i['FX'], e))
                    is_success = deal_price.insert_db()
示例#2
0
    def deal_price(self):
        for data in collection.find(no_cursor_timeout=True):
            if 'fj_flag' in data:
                if data['fj_flag'] == 1:
                    second_price = Comm(self.source)
                    second_price.city = data['fj_city']
                    second_price.direction = data['CJ_CX']
                    second_price.avg_price = float(data['CJ_CJDJ'])
                    second_price.area = float(data['CJ_JZMJ'])
                    second_price.trade_date = data['CJ_CJRQ']

                    second_price.total_price = float(data['CJ_CJDJ']) * float(
                        data['CJ_JZMJ'])

                    second_price.district_name = data['fj_name']
                    if 'CJ_ZH' in data:
                        second_price.house_num = data['CJ_ZH']
                    if 'CJ_SHBW' in data:
                        second_price.room_num = data['CJ_SHBW']
                    try:
                        second_price.floor = int(data['CJ_CS'])
                    except Exception as e:
                        print('楼层error', e)
                    second_price.region = data['fj_region']
                    is_success = second_price.insert_db()
示例#3
0
def into_mongo(coll):
    com = Comm('澜斯')
    results = coll.find(no_cursor_timeout=True)
    for result in results:
        # 这个地方写一个try是因为我再测试的时候发现有的木有fj_city
        try:
            com.city = result['fj_city']  # 城市
            com.region = result['fj_region']  # 区域
        except Exception as e:
            log.error('城市或者区域没有')

        com.m_date = result['updatedate']  # 更新日期
        com.create_date = datetime.datetime.now()  # 创建时间
        com.fitment = result['newdiskdecoration']  # 装修
        com.floor = result['flevel']  # 所在楼层

        # try是因为在插入数据库中这几个如果不符合,就不会插入
        try:
            com.district_name = result['fj_name']  # 小区名称
            com.avg_price = result['unitprice']  # 单价
            com.total_price = result['usd']  # 总价
            com.area = result['acreage']  # 面积=建筑面积

            t = time.strptime(result['signingdate'].split('T')[0], "%Y-%m-%d")
            y = t.tm_year
            m = t.tm_mon
            d = t.tm_mday
            com.trade_date = datetime.datetime(y, m, d)

        except Exception as e:
            log.error(e)

        # 这一部分我写了正则从地址中匹配单元号和室号,如果组长感觉不对,,直接注释掉就好
        houseaddress = result['houseaddress']
        try:
            res = re.search('(\d+)号(\d+)', houseaddress)
            com.unit_num = res.group(1)  # 单元号
            com.room_num = res.group(2)  # 室号
        except Exception as e:
            print('无法匹配大盘单元号和室号,houseaddress={}'.find(houseaddress))

        # 以下数据库确定无法匹配,写上是为了让您看看
        # com.direction = None  # 朝向
        # com.room = None  # 室数
        # com.hall = None  # 厅数
        # com.toilet = None  # 卫数
        # com.height = None  # 总楼层
        # com.house_num = None  # 楼栋号

        # 执行插入操作
        com.insert_db()