Esempio n. 1
0
def read_sheet(spreadsheet_Id, range="A:F"):
    """"""
    result = sheet.values().get(spreadsheetId=spreadsheet_Id,
                                range=range).execute()
    values = result.get("values", [])

    return values
Esempio n. 2
0
def create_sheet(spreadsheetId, test_name):
    """
    New sheet in spreadsheet is created

    :sheet: Google sheet API function
    :spreadsheetId
    :test_name: range to graph up the data, it will be mostly sheet name
    """
    sheet_info = get_sheet(spreadsheetId, [])["sheets"]

    # Create sheet if it doesn't exit
    if not check_sheet_exists(sheet_info, test_name):
        sheet_count = len(sheet_info)

        requests = {
            "addSheet": {
                "properties": {
                    "sheetId": sheet_count + 1,
                    "title": test_name,
                    "gridProperties": {
                        "frozenRowCount": 1,
                    },
                }
            }
        }

        body = {"requests": requests}

        sheet.batchUpdate(spreadsheetId=spreadsheetId, body=body).execute()

        if test_name == "linpack":
            # Add header rows
            values = [LINPACK_HEADER_ROW]

            body = {"values": values}

            sheet.values().update(
                spreadsheetId=spreadsheetId,
                range=test_name,
                valueInputOption="USER_ENTERED",
                body=body,
            ).execute()
Esempio n. 3
0
def append_to_sheet(spreadsheet_Id, results, range="A:F"):
    """"""

    body = {"values": results}

    response = (sheet.values().append(
        spreadsheetId=spreadsheet_Id,
        range=range,
        valueInputOption="USER_ENTERED",
        body=body,
    ).execute())
    return response
Esempio n. 4
0
def create_spreadsheet(spreadsheet_name, test_name):
    """
    A new sheet is created if spreadsheetId is None

    :sheet: Google sheet API function
    :name: Spreadsheet title
    """
    spreadsheet = {
        "properties": {
            "title": spreadsheet_name
        },
        "sheets": {
            "properties": {
                "sheetId": 0,
                "title": test_name,
                "gridProperties": {
                    "frozenRowCount": 1,
                },
            }
        },
    }

    spreadsheet = sheet.create(body=spreadsheet,
                               fields="spreadsheetId").execute()
    spreadsheetId = spreadsheet["spreadsheetId"]

    if test_name == "linpack":
        # Add header rows
        values = [LINPACK_HEADER_ROW]

        body = {"values": values}

        sheet.values().update(
            spreadsheetId=spreadsheetId,
            range=test_name,
            valueInputOption="USER_ENTERED",
            body=body,
        ).execute()

    return spreadsheetId
Esempio n. 5
0
def clear_sheet_data(spreadsheetId, range="A2:Z1000"):
    # Clear values
    sheet.values().clear(spreadsheetId=spreadsheetId, range=range,
                         body={}).execute()