Created
February 7, 2020 20:32
-
-
Save jnalley/69acaf75d81127c2758370aaa169cf8c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gspread | |
from gspread_dataframe import get_as_dataframe | |
from oauth2client.service_account import ServiceAccountCredentials | |
class GoogleSheets: | |
def __init__(self, credentials): | |
scope = ["https://www.googleapis.com/auth/drive"] | |
self.gc = gspread.authorize( | |
ServiceAccountCredentials.from_json_keyfile_dict( | |
credentials, scope | |
) | |
) | |
def open_by_key(self, key, wks=0, df=True): | |
sht = self.gc.open_by_key(key) | |
if wks is None: | |
return sht | |
if isinstance(wks, int): | |
worksheet = sht.get_worksheet(wks) | |
else: | |
worksheet = sht.worksheet(wks) | |
if df is not True: | |
return worksheet | |
return get_as_dataframe(worksheet) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment