예제 #1
0
def process_sheet(sheet, workbook):   
    services = []    
    sheet_ranges = workbook[sheet]    
    columnDict = get_columns_index(sheet_ranges)

    max_col = sheet_ranges.rows.gi_frame.f_locals['max_col']
    max_row = sheet_ranges.rows.gi_frame.f_locals['max_row']

    STARTING_SERVICE_ROW = 2

    for row in sheet_ranges.iter_rows(min_row=STARTING_SERVICE_ROW, max_col=max_col, max_row=max_row):
        fields = {}
        for cell in row: 
            if hasattr(cell,'column') and  cell.column in columnDict.keys():
                fields[columnDict[cell.column]] = cell.value
            else:
                continue
        
        if len(fields) == 0:
            continue

        service = Service(fields)
        if service.is_valid_service():
            services.append(service)
        
    print('Services for ' + sheet + ' has been processed')   
    return services
예제 #2
0
def process_sheet(sheet, workbook, services=[]):
    if services is None:
        services = []
    if not is_valid_sheet_name(sheet):
        print(sheet + ' is not a valid sheet name.')
        return services

    sheet_ranges = workbook[sheet]

    columnDict = get_columns_index(sheet_ranges)

    try:
        assert sheet_ranges['A5'].value is not None
        local = sheet_ranges['A5'].value
        localData = local.split(':')
    except AssertionError:
        print(
            'File is not in correct format. Cell "A5" has no destination nor origin information'
        )
        sys.exit(FILE_FORMAT_ERROR)

    origin = ''
    destination = ''

    if 'ORG' in localData[0]:
        origin = localData[1].strip()
    else:
        destination = localData[1].strip()

    max_col = sheet_ranges.rows.gi_frame.f_locals['max_col']
    max_row = sheet_ranges.rows.gi_frame.f_locals['max_row']

    for row in sheet_ranges.iter_rows(min_row=9,
                                      max_col=max_col,
                                      max_row=max_row):
        fields = {}
        for cell in row:
            if hasattr(cell, 'column') and cell.column in columnDict.keys():
                fields[columnDict[cell.column]] = cell.value
            else:
                continue

        if len(fields) == 0:
            continue

        if origin:
            fields['origin'] = origin
        else:
            fields['destination'] = destination

        service = Service(fields)
        if service.is_valid_service():
            result = [
                serviceToFilter for serviceToFilter in services
                if service.paxName == serviceToFilter.paxName
            ]
            if result:
                indx = services.index(result[0])
                previous_service = services[indx]
                services.remove(result[0])
                existing_service = put_in_connection_of_service(
                    previous_service, service)
                services.append(existing_service)
                current_service = put_in_connection_of_service(
                    service, previous_service)
                services.append(current_service)
            else:
                services.append(service)

    print('Services for ' + sheet + ' has been processed')
    return services