How to use the pygsheets.authorize function in pygsheets

To help you get started, we’ve selected a few pygsheets examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github avrae / avrae / test / sheets / autogsheet.py View on Github external
def main():
    gc = pygsheets.authorize(service_file='./avrae-0b82f09d7ab3.json')

    template = gc.open_by_key(TEMPLATE_SPREADSHEET_ID)  # open template
    new_sheet = gc.create("TESTNew CharacterTEST", parent_id=PARENT_FOLDER_ID)  # create new character sheet

    template.sheet1.copy_to(new_sheet.id)  # copy character sheet over
    new_sheet.del_worksheet(new_sheet.sheet1)  # delete default worksheet
    new_sheet.worksheet().title = "v1.3"  # pretty it a little

    feature_cell_index = 0

    feature_cell_index = do_race(new_sheet.worksheet(), feature_cell_index)
    feature_cell_index = do_class_and_level(new_sheet.worksheet(), feature_cell_index)
    email = input("Please enter your Google account email: ")
    new_sheet.share(email, role='writer')  # give control to user
github frdmn / google-speedtest-chart / speedtest-charts.py View on Github external
def get_credentials():
    """Function to check for valid OAuth access tokens."""
    gc = pygsheets.authorize(outh_file="credentials.json")
    return gc
github nithinmurali / pygsheets / test / update_gsheet.py View on Github external
parser.add_argument('-rh','--replace', help='replace the header if exists', action='store_true')
args = parser.parse_args()
#csv_file = args.file
gs_link = args.gs_ws

#print(args.gs_ss)

__location__ = os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__)))
weekly_data = defaultdict(list) # each value in each column is appended to a list
with open(os.path.join(__location__,'data_final.csv')) as f:
    reader = csv.DictReader(f) # read rows into a dictionary format
    for row in reader: # read a row as {column1: value1, column2: value2,...}
        for (k,v) in row.items(): # go over each column name and value 
            weekly_data[k].append(v) # append the value into the appropriate list

gc = pygsheets.authorize()
wks = ''
if args.sheet_name:
    wks = gc.open_by_key(gs_link).worksheet('title',args.sheet_name)
else:
    wks = gc.open_by_key(gs_link).get_worksheet('id',args.gs_ss)

print "updating the sheet, ", wks.title

max_rows = 125
max_cols = 4  # cols with matrices
week_start_index = 5
colsDicts = []

def createDict(ilist):
    #print(ilist)
    nkey = "none"
github jeromegit / audible2sheet / audible2sheet / audible2sheet.py View on Github external
def get_gs_wks(gs_cfg, root_path):
    """
    Get a Google Sheet API handle to get/set worksheet data
    """
    # GS cfg data
    creds_file_path = create_full_path(gs_cfg.get('creds_file_path'), root_path)
    sheet_name      = gs_cfg.get('sheet_name', 'my_audible_books_generated_by_audible2sheet')
    gs_email        = gs_cfg.get('email')
    
    gc = pygsheets.authorize(service_file=creds_file_path)
    try: 
        sheet = gc.open(sheet_name)
    except pygsheets.SpreadsheetNotFound as error:
        # Can't find it and so create it
        res = gc.sheet.create(sheet_name)
        sheet_id = res['spreadsheetId']
        sheet = gc.open_by_key(sheet_id)
        print(f"Created spreadsheet with id:{sheet.id} and url:{sheet.url}")

        # Share with self to allow to write to it
        sheet.share(gs_email, role='writer', type='user')

        # Share to all for reading
        sheet.share('', role='reader', type='anyone')
        wks = sheet.sheet1
github noeltrivedi / beer_pong_bot / chomps / sheetsdecorator.py View on Github external
def _init_pygsheets(self):
        self.gc = pygsheets.authorize(service_file=self.credentials)
github salesforce / pygsheetsorm / pygsheetsorm / pygsheetsorm.py View on Github external
"""Factory method to return a Repository given signed crednentials,
        spreadsheet id, and name of sheet.

        Args:
          service_account_file (str): Service account key file (JSON) from google
              https://pygsheets.readthedocs.io/en/stable/authorizing.html#signed-credentials
          spreadsheet_id (str): The ID of the google spreadsheet to retrieve data from.
          sheet_name (str): Name of sheet in spreadhseet to read/write to.
                            Default value = "Sheet1"

        Returns:
          Repository: Repository created with arguments

        """
        try:
            client = pygsheets.authorize(service_account_file=service_account_file)
            spreadsheet = client.open_by_key(spreadsheet_id)
            worksheet = spreadsheet.worksheet_by_title(sheet_name)
            return cls(pygsheets_worksheet=worksheet)
        except HttpError as err:
            if "Requested entity was not found" in err._get_reason():
                raise SpreadsheetException(
                    "Error connecting to Google Sheets. " "Check your spreadsheet ID."
                )
            raise