How to use the gspread.Client function in gspread

To help you get started, we’ve selected a few gspread 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 phillipian / upload-automation / src / local / fetch_sheet.py View on Github external
def get_google_sheet(spreadsheet_url, section):
    """ Retrieve sheet data using OAuth credentials and Google Python API. """
    SCOPES = ['https://spreadsheets.google.com/feeds',
         'https://www.googleapis.com/auth/drive']
    SERVICE_ACCT_FILE = os.path.join(os.getcwd(), 'client_secret.json')

    credentials = service_account.Credentials.from_service_account_file(SERVICE_ACCT_FILE, scopes=SCOPES)
    client = gspread.Client(auth=credentials)
    client.session = AuthorizedSession(credentials)

    sheet = client.open_by_url(spreadsheet_url) # for spreadsheet by URL
    # sheet1 = client.open(spreadsheet_id).sheet1 # for spreadsheet by NAME

    # convert sheet to dataframe
    section_sheet = sheet.worksheet(section)
    values = section_sheet.get_all_values()
    #print(section_sheet.col_values(1, 'FORMULA'))
    #links = pd.DataFrame(section_sheet.col_values(1, 'FORMULA')[2:])
    section_sheet_df = pd.DataFrame(values[2:])

    # rename columns
    col_names = section_sheet_df[0:1].values[0]
    section_sheet_df = section_sheet_df[1:]
    section_sheet_df.columns = col_names
github getredash / redash / redash / query_runner / google_spreadsheets.py View on Github external
def _get_spreadsheet_service(self):
        scope = [
            'https://spreadsheets.google.com/feeds',
        ]

        key = json_loads(b64decode(self.configuration['jsonKeyFile']))
        creds = ServiceAccountCredentials.from_json_keyfile_dict(key, scope)

        timeout_session = Session()
        timeout_session.requests_session = TimeoutSession()
        spreadsheetservice = gspread.Client(auth=creds, session=timeout_session)
        spreadsheetservice.login()
        return spreadsheetservice
github phillipian / upload-automation / get_data.py View on Github external
def get_google_sheet(spreadsheet_url, section):
    """ Retrieve sheet data using OAuth credentials and Google Python API. """
    SCOPES = ['https://spreadsheets.google.com/feeds',
         'https://www.googleapis.com/auth/drive']
    SERVICE_ACCT_FILE = '../client_secret.json'

    credentials = service_account.Credentials.from_service_account_file(SERVICE_ACCT_FILE, scopes=SCOPES)
    client = gspread.Client(auth=credentials)
    client.session = AuthorizedSession(credentials)
  
    sheet = client.open_by_url(spreadsheet_url) # for spreadsheet by URL
    # sheet1 = client.open(spreadsheet_id).sheet1 # for spreadsheet by NAME

    section_sheet = sheet.worksheet(section)

    values = section_sheet.get_all_values()
    section_sheet_data = pd.DataFrame(values[2:])
    return section_sheet_data
github phillipian / upload-automation / fetch_sheet.py View on Github external
def get_google_sheet(spreadsheet_url, section):
    """ Retrieve sheet data using OAuth credentials and Google Python API. """
    SCOPES = ['https://spreadsheets.google.com/feeds',
         'https://www.googleapis.com/auth/drive']
    SERVICE_ACCT_FILE = '../client_secret.json'

    credentials = service_account.Credentials.from_service_account_file(SERVICE_ACCT_FILE, scopes=SCOPES)
    client = gspread.Client(auth=credentials)
    client.session = AuthorizedSession(credentials)

    sheet = client.open_by_url(spreadsheet_url) # for spreadsheet by URL
    # sheet1 = client.open(spreadsheet_id).sheet1 # for spreadsheet by NAME

    # convert sheet to dataframe
    section_sheet = sheet.worksheet(section)
    values = section_sheet.get_all_values()
    #print(section_sheet.col_values(1, 'FORMULA'))
    #links = pd.DataFrame(section_sheet.col_values(1, 'FORMULA')[2:])
    section_sheet_df = pd.DataFrame(values[2:])

    # rename columns
    col_names = section_sheet_df[0:1].values[0]
    section_sheet_df = section_sheet_df[1:]
    section_sheet_df.columns = col_names