コード例 #1
0
def type_one_cover_search_2_images(path):
    cover_search = OpenExcel(path)
    starts = []
    for r in range(cover_search.getRows()):
        pass
        # Todo
    row = 15
    done = False
    images = []
    while not done:
        row_data = cover_search.read(row)
        if row_data[1] == "":
            done = True
        else:
            new_image = AerialImage(row_data[1], int(row_data[2]),
                                    int(row_data[4]), row_data[6],
                                    int(row_data[8]), row_data[9],
                                    row_data[12], int(row_data[14]),
                                    int(row_data[15]), row_data[16])
            images.append(new_image)
        row += 1
    return images
コード例 #2
0
def analise_cover_search(path):
    random_ref = hex(random.randint(1, 4294967296)).upper().strip("0X")
    cover_search = OpenExcel(path)
    data = cover_search.read()
    # Find Table Starts
    found_start = False
    table_starts = []
    sheet_width = cover_search.getCols()
    sheet_height = cover_search.getRows()
    for c in range(sheet_width):
        for r in range(sheet_height):
            cell_data = cover_search.read("{}{}".format(ALPHABET[c], r + 1))
            if ("SORTIE" in str(cell_data).upper()) and (
                    "TOTAL" not in str(cell_data).upper()):
                found_start = True
                table_starts.append((c, r))
        if found_start:
            break
        else:
            pass

    items = []
    for start in table_starts:
        headers = []  # To be list of (column, "header text")

        current_row = start[1]
        data_started = False
        while not data_started:
            current_row += 1
            first_cell_address = "{}{}".format(ALPHABET[start[0]],
                                               current_row + 1)
            try:
                cell_data = cover_search.read(first_cell_address)
            except IndexError:
                print("Failed at: {}".format(first_cell_address))
                raise
            if cell_data.count("/") > 0:
                data_started = True
            else:
                pass

        empty_cols = []
        for c in range(sheet_width):
            cell_data = cover_search.read("{}{}".format(
                ALPHABET[c], current_row + 1))
            if cell_data == "":
                empty_cols.append(c)
            else:
                headers.append([ALPHABET[c], ""])

        for c, h in enumerate(headers):
            cell_data = cover_search.read("{}{}".format(h[0], start[1] + 1))
            if cell_data == "":
                headers[c][1] = "{}:{}".format(random_ref, [c][0])
            else:
                headers[c][1] = cell_data.strip()

        data_started = False
        data_finished = False
        current_row = start[1] + 1

        while not data_finished:
            first_cell_address = "{}{}".format(headers[0][0], current_row + 1)
            try:
                cell_data = cover_search.read(first_cell_address)
            except IndexError:
                data_finished = True
                break

            if cell_data.count("/") > 0:
                data_started = True
            else:
                pass

            new_item = dict()
            for i, h in enumerate(headers):
                cell_address = "{}{}".format(h[0], current_row + 1)
                cell_data = cover_search.read(cell_address)
                if not data_started:
                    if cell_data != "":
                        headers[i][1] += " {}".format(cell_data)
                    else:
                        pass
                else:
                    if (i == 0) and (cell_data.count("/") < 1):
                        data_finished = True
                        break
                    else:
                        new_item[h[1]] = cell_data

            if new_item == dict():
                pass
            else:
                new_item["originating_file"] = path
                items.append(new_item)

            current_row += 1
    return items