Esempio n. 1
0
def parse_page(content, price_dict):

    tickets = []
    results = {}
    flights = {}

    try:
        json_temp = json.loads(content)
    except:
        results['ticket'] = tickets
        results['flight'] = flights
        return results

    if json_temp['Status'] == 'SUCCESS':
        for each_flight_json in json_temp['datalist']:
            roundflight = RoundFlight()
            #print '---------------'
            try:
                flight_no = each_flight_json['Key']
                #print flight_no

                flight_no_a = flight_no.split('^')[0]
                flight_no_b = flight_no.split('^')[1]
                a_num = len(flight_no_a.split('_'))
                b_num = len(flight_no_b.split('_'))

                roundflight.stop_A = a_num - 1
                roundflight.stop_B = b_num - 1

                roundflight.flight_no_A = flight_no_a
                roundflight.flight_no_B = flight_no_b

                roundflight.dept_id = each_flight_json['ODO'][0]['OL']
                roundflight.dest_id = each_flight_json['ODO'][a_num]['OL']
                #print roundflight.dept_id, roundflight.dest_id

                roundflight.dept_time_A = each_flight_json['ODO'][0]['DD']
                roundflight.dest_time_A = each_flight_json['ODO'][a_num -
                                                                  1]['AD']
                if len(roundflight.dept_time_A) < 17:
                    roundflight.dept_time_A = roundflight.dept_time_A + ':00'
                if len(roundflight.dest_time_A) < 17:
                    roundflight.dest_time_A = roundflight.dest_time_A + ':00'
                #print roundflight.dept_time_A,roundflight.dest_time_A

                roundflight.dept_time_B = each_flight_json['ODO'][a_num]['DD']
                roundflight.dest_time_B = each_flight_json['ODO'][-1]['AD']
                if len(roundflight.dept_time_B) < 17:
                    roundflight.dept_time_B = roundflight.dept_time_B + ':00'
                if len(roundflight.dest_time_B) < 17:
                    roundflight.dest_time_B = roundflight.dest_time_B + ':00'
                #print roundflight.dept_time_B, roundflight.dest_time_B

                roundflight.dept_day = roundflight.dept_time_A.split('T')[0]
                roundflight.dest_day = roundflight.dept_time_B.split('T')[0]

                #roundflight.price = each_flight_json['AIP'][0]['EA']
                price_key = roundflight.flight_no_A + '^' + roundflight.flight_no_B
                roundflight.price = price_dict[price_key]
                roundflight.tax = each_flight_json['AIP'][0]['TX']
                roundflight.source = 'jijitong::jijitong'
                roundflight.seat_type_A = '经济舱'
                roundflight.seat_type_B = '经济舱'
                roundflight.currency = 'CNY'

                #print a_num
                #print roundflight.seat_type_A
                plane_no_a = ''
                airline_a = ''
                for dept_flight in each_flight_json['ODO'][:a_num]:
                    plane_no_a = plane_no_a + dept_flight['EQ'].encode(
                        'utf-8') + '_'
                    airline_a = airline_a + dept_flight['COA'].encode(
                        'utf-8') + '_'
                #print plane_no_a,airline_a
                roundflight.plane_no_A = plane_no_a[:-1]
                roundflight.airline_A = airline_a[:-1]
                #print roundflight.airline_A,roundflight.plane_no_A

                plane_no_b = ''
                airline_b = ''
                for dest_flight in each_flight_json['ODO'][a_num:]:
                    plane_no_b = plane_no_b + dest_flight['EQ'].encode(
                        'utf-8') + '_'
                    airline_b = airline_b + dest_flight['COA'].encode(
                        'utf-8') + '_'
                roundflight.plane_no_B = plane_no_b[:-1]
                roundflight.airline_B = airline_b[:-1]
                #print roundflight.airline_B,roundflight.plane_no_B

                if a_num == 1:
                    dur_A_temp = each_flight_json['ODO'][0]['ET']
                    roundflight.dur_A = int(dur_A_temp) * 60
                else:
                    dur_A_temp = 0
                    dur_A_temp2 = 0
                    for dept_content in each_flight_json['ODO'][:a_num]:
                        dur_A_temp += int(dept_content['ET']) * 60

                    for x in range(1, a_num):
                        #print x
                        dept_time_str = each_flight_json['ODO'][x - 1]['AD']
                        #print dept_time_str
                        dest_time_str = each_flight_json['ODO'][x]['DD']
                        #print dest_time_str
                        dur_A_temp2 += durCal(dept_time_str, dest_time_str)
                        #print dur_A_temp2
                    roundflight.dur_A = dur_A_temp + dur_A_temp2

                if b_num == 1:
                    dur_B_temp = each_flight_json['ODO'][a_num]['ET']
                    roundflight.dur_B = int(dur_B_temp) * 60
                else:
                    dur_B_temp = 0
                    dur_B_temp2 = 0
                    for dept_content in each_flight_json['ODO'][a_num:]:
                        dur_B_temp += int(dept_content['ET']) * 60

                    for x in range(a_num + 1, a_num + b_num):
                        dept_time_str = each_flight_json['ODO'][x - 1]['AD']
                        dest_time_str = each_flight_json['ODO'][x]['DD']
                        dur_B_temp2 += durCal(dept_time_str, dest_time_str)

                    roundflight.dur_B = dur_B_temp + dur_B_temp2

                for eachflight_content in each_flight_json['ODO']:

                    eachflight = EachFlight()

                    try:
                        eachflight.flight_no = eachflight_content['MA']
                        eachflight.dept_id = eachflight_content['OL']
                        eachflight.dest_id = eachflight_content['DL']
                        eachflight.airline = eachflight_content['COA']
                        eachflight.plane_no = eachflight_content['EQ']
                        eachflight.dept_time = eachflight_content['DD'] + ':00'
                        eachflight.dest_time = eachflight_content['AD'] + ':00'
                        eachflight.dur = int(eachflight_content['ET']) * 60

                        eachflight.flight_key = eachflight.flight_no + '_' + eachflight.dept_id + '_' + eachflight.dest_id

                        eachflight_tuple = (eachflight.flight_no, eachflight.airline, eachflight.plane_no, eachflight.dept_id, \
                                eachflight.dest_id, eachflight.dept_time, eachflight.dest_time, eachflight.dur)
                        flights[eachflight.flight_key] = eachflight_tuple

                    except Exception, e:
                        #logger.info('Parse this flight failed with error :' + str(e))
                        continue

                roundflight_tuple = (roundflight.dept_id, roundflight.dest_id, roundflight.dept_day, roundflight.dest_day, \
                    roundflight.price, roundflight.tax, roundflight.surcharge, roundflight.currency, roundflight.source, \
                    roundflight.return_rule, roundflight.flight_no_A, roundflight.airline_A, roundflight.plane_no_A, \
                    roundflight.dept_time_A, roundflight.dest_time_A, roundflight.dur_A, roundflight.seat_type_A, \
                    roundflight.stop_A, roundflight.flight_no_B, roundflight.airline_B, roundflight.plane_no_B, \
                    roundflight.dept_time_B, roundflight.dest_time_B, roundflight.dur_B, roundflight.seat_type_B, \
                    roundflight.stop_B)
                tickets.append(roundflight_tuple)

            except Exception, e:
                logger.error('Can not parse flight info!' + str(e))
                continue
Esempio n. 2
0
            for each_flight_content in outbound_info_list[7]:

                each_flight_dict = eachflightParser(each_flight_content)
                if each_flight_dict != {}:
                    flights.update(each_flight_dict)

                flight_no_A += each_flight_content[2] + each_flight_content[10] + '_'
                plane_no_A += each_flight_content[12] + '_'
                airline_A += airline_dict[each_flight_content[2]] + '_'

            roundflight.plane_no_A = plane_no_A[:-1]
            roundflight.flight_no_A = flight_no_A[:-1]
            roundflight.airline_A = airline_A[:-1]
            roundflight.stop_A = len(outbound_info_list[7]) - 1
            roundflight.stop_B = len(inbound_info_list[7]) - 1

            flight_no_B = ''
            airline_B = ''
            plane_no_B = ''

            for each_flight_content in inbound_info_list[7]:

                each_flight_dict = eachflightParser(each_flight_content)
                if each_flight_dict != {}:
                    flights.update(each_flight_dict)

                flight_no_B += each_flight_content[2] + each_flight_content[10] + '_'
                airline_B += airline_dict[each_flight_content[2]] + '_'
                plane_no_B += each_flight_content[12] + '_'
Esempio n. 3
0
def parse_page(content, price_dict):

    tickets = []
    results = {}
    flights = {}

    try:
        json_temp = json.loads(content)
    except:
        results['ticket'] = tickets
        results['flight'] = flights
        return results


    if json_temp['Status'] == 'SUCCESS':
        for each_flight_json in json_temp['datalist']:
            roundflight = RoundFlight()
            #print '---------------'
            try:
                flight_no = each_flight_json['Key']
                #print flight_no

                flight_no_a = flight_no.split('^')[0]
                flight_no_b = flight_no.split('^')[1]
                a_num = len(flight_no_a.split('_'))
                b_num = len(flight_no_b.split('_'))

                roundflight.stop_A = a_num - 1
                roundflight.stop_B = b_num - 1


                roundflight.flight_no_A = flight_no_a
                roundflight.flight_no_B = flight_no_b

                roundflight.dept_id = each_flight_json['ODO'][0]['OL']
                roundflight.dest_id = each_flight_json['ODO'][a_num]['OL']
                #print roundflight.dept_id, roundflight.dest_id

                roundflight.dept_time_A = each_flight_json['ODO'][0]['DD']
                roundflight.dest_time_A = each_flight_json['ODO'][a_num-1]['AD']
                if len(roundflight.dept_time_A) < 17:
                    roundflight.dept_time_A = roundflight.dept_time_A + ':00'
                if len(roundflight.dest_time_A) < 17:
                    roundflight.dest_time_A = roundflight.dest_time_A + ':00'
                #print roundflight.dept_time_A,roundflight.dest_time_A

                roundflight.dept_time_B = each_flight_json['ODO'][a_num]['DD']
                roundflight.dest_time_B = each_flight_json['ODO'][-1]['AD']
                if len(roundflight.dept_time_B) < 17:
                    roundflight.dept_time_B = roundflight.dept_time_B + ':00'
                if len(roundflight.dest_time_B) < 17:
                    roundflight.dest_time_B = roundflight.dest_time_B + ':00'
                #print roundflight.dept_time_B, roundflight.dest_time_B

                roundflight.dept_day = roundflight.dept_time_A.split('T')[0]
                roundflight.dest_day = roundflight.dept_time_B.split('T')[0]

                #roundflight.price = each_flight_json['AIP'][0]['EA']
                price_key = roundflight.flight_no_A + '^' + roundflight.flight_no_B
                roundflight.price = price_dict[price_key]
                roundflight.tax = each_flight_json['AIP'][0]['TX']
                roundflight.source = 'jijitong::jijitong'
                roundflight.seat_type_A = '经济舱'
                roundflight.seat_type_B = '经济舱'
                roundflight.currency = 'CNY'

                #print a_num
                #print roundflight.seat_type_A
                plane_no_a = ''
                airline_a = ''
                for dept_flight in each_flight_json['ODO'][:a_num]:
                    plane_no_a = plane_no_a + dept_flight['EQ'].encode('utf-8') + '_'
                    airline_a = airline_a + dept_flight['COA'].encode('utf-8') + '_'
                #print plane_no_a,airline_a
                roundflight.plane_no_A = plane_no_a[:-1]
                roundflight.airline_A = airline_a[:-1]
                #print roundflight.airline_A,roundflight.plane_no_A

                plane_no_b = ''
                airline_b = ''
                for dest_flight in each_flight_json['ODO'][a_num:]:
                    plane_no_b = plane_no_b + dest_flight['EQ'].encode('utf-8') + '_'
                    airline_b = airline_b + dest_flight['COA'].encode('utf-8') + '_'
                roundflight.plane_no_B = plane_no_b[:-1]
                roundflight.airline_B = airline_b[:-1]
                #print roundflight.airline_B,roundflight.plane_no_B

                if a_num == 1:
                    dur_A_temp = each_flight_json['ODO'][0]['ET']
                    roundflight.dur_A = int(dur_A_temp) * 60
                else:
                    dur_A_temp = 0
                    dur_A_temp2 = 0
                    for dept_content in each_flight_json['ODO'][:a_num]:
                        dur_A_temp += int(dept_content['ET']) * 60

                    for x in range(1,a_num):
                        #print x
                        dept_time_str = each_flight_json['ODO'][x-1]['AD']
                        #print dept_time_str
                        dest_time_str = each_flight_json['ODO'][x]['DD']
                        #print dest_time_str
                        dur_A_temp2 += durCal(dept_time_str, dest_time_str)
                        #print dur_A_temp2
                    roundflight.dur_A = dur_A_temp + dur_A_temp2

                if b_num == 1:
                    dur_B_temp = each_flight_json['ODO'][a_num]['ET']
                    roundflight.dur_B = int(dur_B_temp) * 60
                else:
                    dur_B_temp = 0
                    dur_B_temp2 = 0
                    for dept_content in each_flight_json['ODO'][a_num:]:
                        dur_B_temp += int(dept_content['ET']) * 60

                    for x in range(a_num+1,a_num+b_num):
                        dept_time_str = each_flight_json['ODO'][x-1]['AD']
                        dest_time_str = each_flight_json['ODO'][x]['DD']
                        dur_B_temp2 += durCal(dept_time_str, dest_time_str)

                    roundflight.dur_B = dur_B_temp + dur_B_temp2

                for eachflight_content in each_flight_json['ODO']:

                    eachflight = EachFlight()

                    try:
                        eachflight.flight_no = eachflight_content['MA']
                        eachflight.dept_id = eachflight_content['OL']
                        eachflight.dest_id = eachflight_content['DL']
                        eachflight.airline = eachflight_content['COA']
                        eachflight.plane_no = eachflight_content['EQ']
                        eachflight.dept_time = eachflight_content['DD'] + ':00'
                        eachflight.dest_time = eachflight_content['AD'] + ':00'
                        eachflight.dur = int(eachflight_content['ET']) * 60

                        eachflight.flight_key = eachflight.flight_no + '_' + eachflight.dept_id + '_' + eachflight.dest_id

                        eachflight_tuple = (eachflight.flight_no, eachflight.airline, eachflight.plane_no, eachflight.dept_id, \
                                eachflight.dest_id, eachflight.dept_time, eachflight.dest_time, eachflight.dur)
                        flights[eachflight.flight_key] = eachflight_tuple

                    except Exception, e:
                        #logger.info('Parse this flight failed with error :' + str(e))
                        continue

                roundflight_tuple = (roundflight.dept_id, roundflight.dest_id, roundflight.dept_day, roundflight.dest_day, \
                    roundflight.price, roundflight.tax, roundflight.surcharge, roundflight.currency, roundflight.source, \
                    roundflight.return_rule, roundflight.flight_no_A, roundflight.airline_A, roundflight.plane_no_A, \
                    roundflight.dept_time_A, roundflight.dest_time_A, roundflight.dur_A, roundflight.seat_type_A, \
                    roundflight.stop_A, roundflight.flight_no_B, roundflight.airline_B, roundflight.plane_no_B, \
                    roundflight.dept_time_B, roundflight.dest_time_B, roundflight.dur_B, roundflight.seat_type_B, \
                    roundflight.stop_B)
                tickets.append(roundflight_tuple)

            except Exception,e:
                logger.error('Can not parse flight info!' + str(e))
                continue
Esempio n. 4
0
            roundflight.airline_B = flight_aircorp[:-1]

            roundflight.dept_time_A = timeshifter(go_segments[0]['departureTime'])
            roundflight.dest_time_A = timeshifter(go_segments[-1]['arrivalTime'])

            roundflight.dept_time_B = timeshifter(return_segments[0]['departureTime'])
            roundflight.dest_time_B = timeshifter(return_segments[-1]['arrivalTime'])

            roundflight.seat_type_A = '经济舱'
            roundflight.seat_type_B = '经济舱'

            roundflight.dur_A = go_info['tripTime'] * 60
            roundflight.dur_B = return_info['tripTime'] * 60

            roundflight.stop_A = len(go_segments) - 1
            roundflight.stop_B = len(return_segments) - 1
        
            flights.append(roundflight)

        return flights
    
    return None

def feiquanqiu_task_parser(content):

    result = {}
    result['para'] = []
    result['error'] = 0

    try:
        infos = content.strip().split('&')
Esempio n. 5
0
            for each_flight_content in outbound_info_list[7]:

                each_flight_dict = eachflightParser(each_flight_content)
                if each_flight_dict != {}:
                    flights.update(each_flight_dict)

                flight_no_A += each_flight_content[2] + each_flight_content[
                    10] + '_'
                plane_no_A += each_flight_content[12] + '_'
                airline_A += airline_dict[each_flight_content[2]] + '_'

            roundflight.plane_no_A = plane_no_A[:-1]
            roundflight.flight_no_A = flight_no_A[:-1]
            roundflight.airline_A = airline_A[:-1]
            roundflight.stop_A = len(outbound_info_list[7]) - 1
            roundflight.stop_B = len(inbound_info_list[7]) - 1

            flight_no_B = ''
            airline_B = ''
            plane_no_B = ''

            for each_flight_content in inbound_info_list[7]:

                each_flight_dict = eachflightParser(each_flight_content)
                if each_flight_dict != {}:
                    flights.update(each_flight_dict)

                flight_no_B += each_flight_content[2] + each_flight_content[
                    10] + '_'
                airline_B += airline_dict[each_flight_content[2]] + '_'
                plane_no_B += each_flight_content[12] + '_'