示例#1
0
def sync_lang(sheet: Worksheet):
    raw_sheet_lang = sheet.row_values(1)
    sheet_lang = set(raw_sheet_lang)
    origin_lang = set(language_pack.languages)
    empty_langs = origin_lang - sheet_lang
    if empty_langs:
        data = [raw_sheet_lang + list(empty_langs)]
        acell = f'A1:{ascii_uppercase[len(data[0]) - 1]}1'
        print(f'update {acell} to ', data)
        sheet.update(acell, data)
示例#2
0
def find_lang_start_col(sheet: Worksheet):
    raw_sheet_lang = sheet.row_values(1)
    min_index = None
    for x in language_pack.languages:
        try:
            i = raw_sheet_lang.index(x)
            min_index = i if min_index > i else min_index
        except Exception as e:
            pass
    if min_index:
        start_lang_idx = min_index + 1
    else:
        start_lang_idx = len(raw_sheet_lang) + 1
    return start_lang_idx
def _ensure_sheet_formatting(worksheet: gspread.Worksheet):
    """
    Ensure that the specified worksheet has the correct header row.

    Overwrites the header row if a header mismatch is found.
    """
    worksheet_headers = list(worksheet.row_values(1))
    expected_headers = list(ColumnHeaders.__members__.keys())

    # Check if the current_headers line up with the updated header structure
    if worksheet_headers != expected_headers:
        logger.warning("Prexisting table, with improper formatting: Fixing")
        # TODO: move all data, not just headers
        worksheet.delete_row(1)
        worksheet.insert_row(expected_headers, 1)
    else:
        # TODO: ensure the below is still necessary
        if worksheet.row_count in (0, 1):
            worksheet.insert_row([], 1)
            worksheet.insert_row(expected_headers, 1)
            worksheet.delete_row(3)
        worksheet.delete_row(1)
示例#4
0
def table_from_worksheet(worksheet: gspread.Worksheet, header: Optional[Tuple[str]] = None):
    if header:
        return SpreadsheetTable(worksheet, header=header)

    header = tuple(trim_sequence(worksheet.row_values(1)))
    return SpreadsheetTable(worksheet, header, first_row_index=1)