<reponame>reiji-amano/maya_exploit_SP<filename>google/sendGspread.py
import gspread
import json
import os
import pathlib
from oauth2client.service_account import ServiceAccountCredentials

def update_status_sheet(info={}, index_key="", sheet_key="", json_file=""):
    scope = [
        "https://spreadsheets.google.com/feeds",
        "https://www.googleapis.com/auth/drive",
    ]


    credentials = ServiceAccountCredentials.from_json_keyfile_name(
        json_file,
        scope
    )

    gc = gspread.authorize(credentials)
    workbook = gc.open_by_key(sheet_key)
    sheet = workbook.worksheet('mel')

    head_col = sheet.row_values(1)
    index_col = head_col.index(index_key) + 1

    find_users = sheet.findall(info.get(index_key), in_column=index_col)
    if len(find_users):
        for user in find_users:
            sheet_range = sheet.range(user.row, 1, user.row, len(head_col))
            for index, key in enumerate(head_col):
                sheet_range[index].value = info.get(key)

            result = sheet.update_cells(sheet_range)
            print(result)

    else:
        max_row = len(sheet.col_values(head_col.index(index_key) + 1))
        sheet_range = sheet.range(max_row + 1, 1, max_row + 1, len(head_col))
        # sheet_range
        for index, key in enumerate(head_col):
            sheet_range[index].value = info.get(key)

        result = sheet.update_cells(sheet_range)
        print(result)


if __name__ == "__main__":
    import socket
    info = {
        "username": os.getenv("USERNAME"),
        "host": socket.gethostname(),
        "ip":socket.gethostbyname(socket.gethostname()),
        "result": 1,
        "files":"\n".join([r"C:\Program Files\Autodesk\MayaLT2020\scripts\unsupported\reparameterizeNurbsSurfaceAlongU.mel", r"C:\Program Files\Autodesk\MayaLT2020\scripts\unsupported\reparameterizeNurbsCurve.res.mel"])
    }
    update_status_sheet(info, "host")
import gspread
import json
import os
import pathlib
from oauth2client.service_account import ServiceAccountCredentials

def update_status_sheet(info={}, index_key="", sheet_key="", json_file=""):
    scope = [
        "https://spreadsheets.google.com/feeds",
        "https://www.googleapis.com/auth/drive",
    ]


    credentials = ServiceAccountCredentials.from_json_keyfile_name(
        json_file,
        scope
    )

    gc = gspread.authorize(credentials)
    workbook = gc.open_by_key(sheet_key)
    sheet = workbook.worksheet('mel')

    head_col = sheet.row_values(1)
    index_col = head_col.index(index_key) + 1

    find_users = sheet.findall(info.get(index_key), in_column=index_col)
    if len(find_users):
        for user in find_users:
            sheet_range = sheet.range(user.row, 1, user.row, len(head_col))
            for index, key in enumerate(head_col):
                sheet_range[index].value = info.get(key)

            result = sheet.update_cells(sheet_range)
            print(result)

    else:
        max_row = len(sheet.col_values(head_col.index(index_key) + 1))
        sheet_range = sheet.range(max_row + 1, 1, max_row + 1, len(head_col))
        # sheet_range
        for index, key in enumerate(head_col):
            sheet_range[index].value = info.get(key)

        result = sheet.update_cells(sheet_range)
        print(result)


if __name__ == "__main__":
    import socket
    info = {
        "username": os.getenv("USERNAME"),
        "host": socket.gethostname(),
        "ip":socket.gethostbyname(socket.gethostname()),
        "result": 1,
        "files":"\n".join([r"C:\Program Files\Autodesk\MayaLT2020\scripts\unsupported\reparameterizeNurbsSurfaceAlongU.mel", r"C:\Program Files\Autodesk\MayaLT2020\scripts\unsupported\reparameterizeNurbsCurve.res.mel"])
    }
    update_status_sheet(info, "host")
# sheet_range