How to use the gspread.authorize 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 hplgit / virtual-classroom / virtual_classroom / scripts / View on Github external
parameters_path = os.path.join(os.path.dirname(__file__), '..', 'default_parameters.txt')
lines = open(parameters_path, 'r').readlines()
parameters = {}
for line in lines:
    key, value = line.split(':')
    parameters[key] = value[:-1]

spreadsheet_name = "Sign up form for INF3331/INF43331 (2016) (Responses)"
# or use
# spreadsheet_name = parameters["course"]

# Log on to disk
scope = ['']
credentials = ServiceAccountCredentials.from_json_keyfile_name(json_file, scope)

gc = gspread.authorize(credentials)
    wks =
except gspread.SpreadsheetNotFound:
    json_key = json.load(open(json_file))
    print "The spreadsheet document '{}' not found. Maybe it does not exist?".format(spreadsheet_name)
    print "Otherwise, make sure that you shared the spreadsheet with {} and try again.".format(json_key['client_email'])

# Store file in ../Attendance/
attendance_location = os.path.join(os.path.dirname(__file__), '..',
# Create ../Attendance/ if it does not exist
if not os.path.exists(attendance_location):

filename = os.path.join(attendance_location, "%s-students_base.txt" % parameters['course'])
github DaniloZZZ / tgflow / examples / databases_files / View on Github external
def __init__(self, auth_filepath):
        scope = ['',
        creds = ServiceAccountCredentials.from_json_keyfile_name(auth_filepath, scope)
        self._client = gspread.authorize(creds)
github cajohnst / Optimized_FX_Portfolio / View on Github external
def setup_credentials():
    scope = ['']
    if on_heroku:
        keyfile_dict = setup_keyfile_dict()
        credentials = ServiceAccountCredentials.from_json_keyfile_dict(keyfile_dict, scope)
        credentials = ServiceAccountCredentials.from_json_keyfile_name('My Project-3b0bc29d35d3.json', scope)

    gc = gspread.authorize(credentials)

    if on_heroku:
        sps = gc.open_by_key("1DdmBaOlGGdgQRaaI3tQCxj3BEd8kPwaGIHVfMpIoH8I")
        sps = gc.open_by_key("1DdmBaOlGGdgQRaaI3tQCxj3BEd8kPwaGIHVfMpIoH8I")
    return sps
github Robin-Lord / vietnambot-the-third / View on Github external
# You will need to create the json file referenced below (starting My Project) and upload it to wherever you are
    # hosting this code. You will also need to find the url of your Google sheet, and set it as an ENVIRONMENTAL variable
    # instructions for how to create an environmental variable on Heroku are here:

    # If you consistently can't access the sheet you may have not set up the permissions properly
    # Try sharing the sheet with your SERVICE ACCOUNT email address and see what happens

    # Printing for debugging
    json_key = json.load(open('vietnambot-2017-77539de66304.json'))
    print (app_code,location_code,sublocation, "json key is: ", json_key)

    scope = ['']
    credentials = ServiceAccountCredentials.from_json_keyfile_name('vietnambot-2017-77539de66304.json', scope)

    # Opening the relevant google sheet by name (can also open by URL)
    gc = gspread.authorize(credentials)
    print (app_code,location_code,sublocation,"authorised, gc is: ",gc)
    vietnam ="Vietnamese orders")
    print ("sheet is ", vietnam)
    orders1 = vietnam.get_worksheet(0)
    print (app_code,location_code,sublocation," have called sheet 'orders1' ")

    #running the update_sheet program which takes the user information and adds them to the first empty row in the order sheet



    # Sending message to slack confirming order and signalling that will update with order status
    # (see above for source and reasoning) of the process
    params = (
    ('token', user_token),
github lstern / SWProxy-plugins / plugins / View on Github external
def get_worksheet(self, key, sheet):
        date =
        days_until_saturday = 5 - date.weekday()
        next_saturday = date + datetime.timedelta(days_until_saturday)

        scope = ['']
        credentials = ServiceAccountCredentials.from_json_keyfile_name(key, scope)
        gc = gspread.authorize(credentials)
        sheet_name = 'Guildwar %s' % next_saturday.strftime('%m-%d-%Y')
github bradschm / JSS-Advanced-Search-to-Google-Sheets / View on Github external
def oauthSheets():"Authenticating using OAuth for Google Sheets")
	f = file('%s/%s' % (SITE_ROOT,'data/key/sheets.p12'), 'rb')
	key =
	http = httplib2.Http()
	storage = Storage(SITE_ROOT + '/data/sheets.dat')
	credentials = storage.get()
	if credentials is None or credentials.invalid:
		credentials = SignedJwtAssertionCredentials(google_api_user, key, scope='',sub=google_user)
	http = httplib2.Http()
	http = credentials.authorize(http)
	gc = gspread.authorize(credentials)
	return gc
github cyanfish / heltour / heltour / tournament / View on Github external
def _open_doc(url):
    scope = ['']
    credentials = ServiceAccountCredentials.from_json_keyfile_name(
    gc = gspread.authorize(credentials)
        return gc.open_by_url(url)
    except gspread.SpreadsheetNotFound:
        raise SpreadsheetNotFound