예제 #1
0
            logger.info('Cannot parse breakfast info with error: ' + str(e))

        try:
            if '加床' in room.room_desc:
                room.is_extrabed = 'Yes'
            if '免费加床' in room.room_desc or '加床免费' in room.room_desc:
                room.is_extrabed_free = 'Yes'
        except Exception, e:
            logger.info('Cannor parse extrabed info with error: ' + str(e))

        try:
            try:
                total_price = each_hotel['chargeableRoomRateTotal']
                tax_price = each_hotel['chargeableRoomRateTaxesAndFees']
                room.tax = float(str(tax_price))
                room.price = float(str(total_price)) - room.tax
            except:
                total_price = each_hotel['chargeableRoomRateTotal']
                room.price = float(str(total_price))
                room.tax = 0
        except Exception, e:
            logger.error('Cannot parse this room\'s price with error:' +
                         str(e))
            continue

        try:
            if '三人' in room.room_type or '3' in room.bed_type:
                room.occupancy = 3
            elif '四人' in room.room_type or '4' in room.bed_type:
                room.occupancy = 4
            else:
예제 #2
0
                room.real_source = each_room[2]

                num = each_room[3].find('-')
                if num > 0:
                    if len(each_room[3][:num]) < 20:
                        room.room_type = each_room[3][:num]
                    else:
                        room.room_type = 'NULL'
                else:
                    if len(each_room[3]) < 20:
                        room.room_type = each_room[3]
                    else:
                        room.room_type = 'NULL'
            
                if each_room[0] != u'nbsp;':
                    room.price = each_room[0]
                room.has_breakfast = each_room[1]
                room.room_desc = each_room[3]

                if '免费WiFi' in room.room_desc:
                    room.is_wifi_free = 'Yes'
                
                if '免费取消' in room.room_desc:
                    room.is_cancel_free = 'Yes'

                room.currency = 'CNY'
                room.source = 'youzhan'
                room.source_hotelid = hotel_id
                room.check_in = from_date
                room.check_out = to_date
예제 #3
0
        logger.error('Can not parse rooms info!' + str(e))
        return rooms

    for each_room_info in each_room_info_list:
        room = Room()
        room.hotel_name = hotel_name.replace('_', ' ')
        room.city = city
        room.source_hotelid = hotel_id
        room.currency = 'CNY'
        room.source = 'biyi'
        room.check_in = check_in
        room.check_out = check_out

        try:
            room.real_source = real_source_pat.findall(each_room_info)[0]
            room.price = price_pat.findall(each_room_info)[0].replace(
                ' ', '').replace(',', '')
        except Exception, e:
            #logger.error('Can not parse important info of this room! Detail: ' + str(e))
            return rooms

        other_info = ''
        try:
            other_info = other_info_pat.findall(each_room_info)[0]
            if '免费取消' in other_info:
                room.is_cancel_free = 'Yes'
            else:
                room.is_cancel_free = 'No'
        except:
            room.is_cancel_free = 'No'

        try:
예제 #4
0
            logger.info('Cannot parse breakfast info with error: ' + str(e))

        try:
            if '加床' in room.room_desc:
                room.is_extrabed = 'Yes'
            if '免费加床' in room.room_desc or '加床免费' in room.room_desc:
                room.is_extrabed_free = 'Yes'
        except Exception, e:
            logger.info('Cannor parse extrabed info with error: ' + str(e))

        try:
            try:
                total_price = each_hotel['chargeableRoomRateTotal']
                tax_price = each_hotel['chargeableRoomRateTaxesAndFees']
                room.tax = float(str(tax_price))
                room.price = float(str(total_price)) - room.tax
            except:
                total_price = each_hotel['chargeableRoomRateTotal']
                room.price = float(str(total_price))
                room.tax = 0
        except Exception,e:
            logger.error('Cannot parse this room\'s price with error:' + str(e))
            continue

        try:
            if '三人' in room.room_type or '3' in room.bed_type:
                room.occupancy = 3
            elif '四人' in room.room_type or '4' in room.bed_type:
                room.occupancy = 4
            else:
                room.occupancy = 2
예제 #5
0
def youzhan_task_parser(taskcontent):
    all_info = []
    room_list = []
    taskcontent = taskcontent.encode('utf-8').strip()
    hotel_id = taskcontent.split('&')[0]
    star = taskcontent.split('&')[2]
    ipathid = taskcontent.split('&')[1]
    city = taskcontent.split('&')[3]
    country = taskcontent.split('&')[4]
    #room_type = taskcontent.split('&')[3]
    from_date_temp = taskcontent.split('&')[5]
    from_date = from_date_temp[:4] + '-' + from_date_temp[4:6] + '-' \
                + from_date_temp[6:]
    to_date_temp = datetime.datetime(int(from_date_temp[:4]), int(from_date_temp[4:6]), \
                                     int(from_date_temp[6:]))
    to_date = str(to_date_temp + datetime.timedelta(days = 1))[:10]

    #获取代理
    
    p = get_proxy()

    #if p == "":
        #logger.error("get proxy failed")
        #return None
    
    hotel = Hotel()
    room = Room()

    rating_url = get_rating_url(hotel_id)
    rating_page = crawl_single_page(rating_url, proxy=p)
    
    grade_str = grade_parser(rating_page)
    
    if grade_str != '':
        hotel.grade = grade_str[:-1]
    else:
        pass
        #logger.error('Error: No grade_str found!')

    map_url = get_map_url(hotel_id)
    map_page = crawl_single_page(map_url, proxy=p)
    #print map_page
    map_info_list = staticmap_parser(map_page)
    if map_info_list != []:
        hotel.hotel_name = map_info_list[1]
        if is_alphabet(hotel.hotel_name.decode('utf-8')) == True:
            hotel.hotel_name_en = hotel.hotel_name
        else:
            hotel.hotel_name_en = 'NULL'
        hotel.map_info = map_info_list[0]
    else:
        logger.error('youzhanHotel: Map info do not have hotel name and map_info')
        return []

    info_url = get_info_url(hotel_id,from_date,to_date)
    info_page = crawl_single_page(info_url,proxy=p)
    if info_page == '':
        #invalid_proxy(p)
        return []
    info_list = info_parser(info_page)

    if info_list != []:
        hotel.country = country
        hotel.city = city
        hotel.address = info_list[1]
        hotel_desc_temp = info_list[3].replace('&lt;br/&gt;','').replace('&#039;','')
        if hotel_desc_temp != '':
            hotel.description = hotel_desc_temp
        else:
            hotel.description = 'NULL'
        hotel.service = info_list[4]

        if '停车场' in hotel.service:
            hotel.has_parking = 'Yes'
        if '无线网络' in hotel.service or 'wifi' in hotel.service:
            hotel.has_wifi = 'Yes'
    else:
        return []

    hotel.source = 'youzhan'
    hotel.source_id = hotel_id
    hotel.star = star

    price_url = get_price_url(hotel_id,ipathid,from_date,to_date)
    price_page = crawl_single_page(price_url,proxy=p)
    price_list = price_parser(price_page,hotel_id)
    #print '********'
    #print price_list
    if price_list != []:
        for each_room in price_list:
            if len(each_room) > 3:
                room.city = city
                room.occupancy = 2
                room.hotel_name = hotel.hotel_name
                #print '******'
                #print each_room
                room.room_desc = each_room[3]
                room.real_source = each_room[2]
                

                num = each_room[3].find('-')
                if num > 0:
                    if len(each_room[3][:num]) < 20:
                        room.room_type = each_room[3][:num]
                    else:
                        room.room_type = 'NULL'
                else:
                    if len(each_room[3]) < 20:
                        room.room_type = each_room[3]
                    else:
                        room.room_type = 'NULL'
            
                if each_room[0] != u'nbsp;':
                    room.price = each_room[0]
                room.has_breakfast = each_room[1]
                room.room_desc = each_room[3]

                if '免费WiFi' in room.room_desc:
                    hotel.is_wifi_free = 'Yes'
                
                if '免费取消' in room.room_desc:
                    hotel.is_cancel_free = 'Yes'

                room.currency = 'CNY'
                room.source = 'youzhan'
                room.source_hotelid = hotel_id
                room.check_in = from_date
                room.check_out = to_date

                room_tuple = (room.hotel_name,room.city,room.source,room.source_hotelid,\
                    room.source_roomid,room.real_source,room.room_type,room.occupancy,\
                    room.bed_type,room.size,room.floor,room.check_in,room.check_out,room.price,\
                    room.tax,room.currency,room.is_extrabed,room.is_extrabed_free,room.has_breakfast,\
                    room.is_breakfast_free,room.is_cancel_free,room.room_desc)
                room_list.append(room_tuple)

    hotel_tuple = (hotel.hotel_name, hotel.hotel_name_en,hotel.source,hotel.source_id,hotel.brand_name,\
        hotel.map_info,hotel.address,hotel.city,hotel.country,hotel.postal_code, \
        hotel.star,hotel.grade,hotel.has_wifi,hotel.is_wifi_free,hotel.has_parking,\
        hotel.is_parking_free,hotel.service,hotel.img_items,hotel.description)
    hotel_list = []
    hotel_list.append(hotel_tuple)
    all_info.append(hotel_list)
    all_info.append(room_list)

    return all_info
예제 #6
0
def youzhan_task_parser(taskcontent):
    all_info = []
    room_list = []
    taskcontent = taskcontent.encode('utf-8').strip()
    hotel_id = taskcontent.split('&')[0]
    star = taskcontent.split('&')[2]
    ipathid = taskcontent.split('&')[1]
    city = taskcontent.split('&')[3]
    country = taskcontent.split('&')[4]
    #room_type = taskcontent.split('&')[3]
    from_date_temp = taskcontent.split('&')[5]
    from_date = from_date_temp[:4] + '-' + from_date_temp[4:6] + '-' \
                + from_date_temp[6:]
    to_date_temp = datetime.datetime(int(from_date_temp[:4]), int(from_date_temp[4:6]), \
                                     int(from_date_temp[6:]))
    to_date = str(to_date_temp + datetime.timedelta(days=1))[:10]

    #获取代理

    p = get_proxy()

    #if p == "":
    #logger.error("get proxy failed")
    #return None

    hotel = Hotel()
    room = Room()

    rating_url = get_rating_url(hotel_id)
    rating_page = crawl_single_page(rating_url, proxy=p)

    grade_str = grade_parser(rating_page)

    if grade_str != '':
        hotel.grade = grade_str[:-1]
    else:
        pass
        #logger.error('Error: No grade_str found!')

    map_url = get_map_url(hotel_id)
    map_page = crawl_single_page(map_url, proxy=p)
    #print map_page
    map_info_list = staticmap_parser(map_page)
    if map_info_list != []:
        hotel.hotel_name = map_info_list[1]
        if is_alphabet(hotel.hotel_name.decode('utf-8')) == True:
            hotel.hotel_name_en = hotel.hotel_name
        else:
            hotel.hotel_name_en = 'NULL'
        hotel.map_info = map_info_list[0]
    else:
        logger.error(
            'youzhanHotel: Map info do not have hotel name and map_info')
        return []

    info_url = get_info_url(hotel_id, from_date, to_date)
    info_page = crawl_single_page(info_url, proxy=p)
    if info_page == '':
        #invalid_proxy(p)
        return []
    info_list = info_parser(info_page)

    if info_list != []:
        hotel.country = country
        hotel.city = city
        hotel.address = info_list[1]
        hotel_desc_temp = info_list[3].replace('&lt;br/&gt;',
                                               '').replace('&#039;', '')
        if hotel_desc_temp != '':
            hotel.description = hotel_desc_temp
        else:
            hotel.description = 'NULL'
        hotel.service = info_list[4]

        if '停车场' in hotel.service:
            hotel.has_parking = 'Yes'
        if '无线网络' in hotel.service or 'wifi' in hotel.service:
            hotel.has_wifi = 'Yes'
    else:
        return []

    hotel.source = 'youzhan'
    hotel.source_id = hotel_id
    hotel.star = star

    price_url = get_price_url(hotel_id, ipathid, from_date, to_date)
    price_page = crawl_single_page(price_url, proxy=p)
    price_list = price_parser(price_page, hotel_id)
    #print '********'
    #print price_list
    if price_list != []:
        for each_room in price_list:
            if len(each_room) > 3:
                room.city = city
                room.occupancy = 2
                room.hotel_name = hotel.hotel_name
                #print '******'
                #print each_room
                room.room_desc = each_room[3]
                room.real_source = each_room[2]

                num = each_room[3].find('-')
                if num > 0:
                    if len(each_room[3][:num]) < 20:
                        room.room_type = each_room[3][:num]
                    else:
                        room.room_type = 'NULL'
                else:
                    if len(each_room[3]) < 20:
                        room.room_type = each_room[3]
                    else:
                        room.room_type = 'NULL'

                if each_room[0] != u'nbsp;':
                    room.price = each_room[0]
                room.has_breakfast = each_room[1]
                room.room_desc = each_room[3]

                if '免费WiFi' in room.room_desc:
                    hotel.is_wifi_free = 'Yes'

                if '免费取消' in room.room_desc:
                    hotel.is_cancel_free = 'Yes'

                room.currency = 'CNY'
                room.source = 'youzhan'
                room.source_hotelid = hotel_id
                room.check_in = from_date
                room.check_out = to_date

                room_tuple = (room.hotel_name,room.city,room.source,room.source_hotelid,\
                    room.source_roomid,room.real_source,room.room_type,room.occupancy,\
                    room.bed_type,room.size,room.floor,room.check_in,room.check_out,room.price,\
                    room.tax,room.currency,room.is_extrabed,room.is_extrabed_free,room.has_breakfast,\
                    room.is_breakfast_free,room.is_cancel_free,room.room_desc)
                room_list.append(room_tuple)

    hotel_tuple = (hotel.hotel_name, hotel.hotel_name_en,hotel.source,hotel.source_id,hotel.brand_name,\
        hotel.map_info,hotel.address,hotel.city,hotel.country,hotel.postal_code, \
        hotel.star,hotel.grade,hotel.has_wifi,hotel.is_wifi_free,hotel.has_parking,\
        hotel.is_parking_free,hotel.service,hotel.img_items,hotel.description)
    hotel_list = []
    hotel_list.append(hotel_tuple)
    all_info.append(hotel_list)
    all_info.append(room_list)

    return all_info
예제 #7
0
        logger.error('Can not parse rooms info!' + str(e))
        return rooms

    for each_room_info in each_room_info_list:
        room = Room()
        room.hotel_name = hotel_name.replace('_',' ')
        room.city = city
        room.source_hotelid = hotel_id
        room.currency = 'CNY'
        room.source = 'biyi'
        room.check_in = check_in
        room.check_out = check_out
        
        try:
            room.real_source = real_source_pat.findall(each_room_info)[0]
            room.price = price_pat.findall(each_room_info)[0].replace(' ','').replace(',','')
        except Exception, e:
            #logger.error('Can not parse important info of this room! Detail: ' + str(e))
            return rooms
        
        other_info = ''
        try:
            other_info = other_info_pat.findall(each_room_info)[0]
            if '免费取消' in other_info:
                room.is_cancel_free = 'Yes'
            else:
                room.is_cancel_free = 'No'
        except:
            room.is_cancel_free = 'No'

        try:
예제 #8
0
            
        #print  room.room_type,room.bed_type
        try:
            room_content_list = each_room_content_pat.findall(each_type_room_content)
            if len(room_content_list) == 0:
                continue
        except Exception, e:
            #logger.info('haodingHotel::Parse this room failed with error: ' + str(e))
            continue

        for each_room_content in room_content_list:
            try:
                price_content_temp = price_temp_pat.findall(each_room_content)[0]
                price_content = re.sub('<.*?>','',price_content_temp).strip()
                price = price_content.replace('¥','').replace(',','')
                room.price = int(price)
                cancel_content_temp = is_cancel_content_pat.findall(each_room_content)[0]
                cancel_content_temp = '<' + cancel_content_temp
                cancel_content = re.sub('<.*?>','',cancel_content_temp).strip()
                if '免费取消' in cancel_content:
                    room.is_cancel_free = 'Yes'
             
                breakfast_content_temp = breakfast_content_pat.findall(each_room_content)[0]
                breakfast_content_temp = '<' + breakfast_content_temp
                breakfast_content = re.sub('<.*?>','',breakfast_content_temp).strip()
                if '早餐' in breakfast_content:
                    room.has_breakfast = 'Yes'
                if '免费' in breakfast_content and '早餐' in breakfast_content:
                    room.has_breakfast = 'Yes'
                    room.is_breakfast_free = 'Yes'
                #print room.price, room.is_cancel_free,room.is_breakfast_free