Skip to content

Instantly share code, notes, and snippets.

@jattoabdul
Created July 10, 2018 17:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jattoabdul/f7fa2b693c4ef962358ea93d464bf71c to your computer and use it in GitHub Desktop.
Save jattoabdul/f7fa2b693c4ef962358ea93d464bf71c to your computer and use it in GitHub Desktop.
Google Sheet API helper for our application using gspread as a python wrapper.
import gspread
from os import path
from config import get_env
from oauth2client.service_account import ServiceAccountCredentials
class GappsHelper:
def __init__(self):
# setup for google sheet - Google Drive API Instance
self.scope = ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']
json_file_path = path.join(path.dirname(__file__), '../../', get_env('CLIENT_SECRET_FILE'))
self.credentials = ServiceAccountCredentials.from_json_keyfile_name(json_file_path, self.scope)
self.client = gspread.authorize(self.credentials)
def open_sheet(self):
sheet = self.client.open(get_env('GAPPS_SHEET_NAME')).sheet1
return sheet.get_all_records(empty2zero=False, head=1, default_blank='')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment