Skip to content

Instantly share code, notes, and snippets.

@thursby
Created June 21, 2019 18:46
Show Gist options
  • Save thursby/d35c5dbc11be9ebaf48bdcbcac3a68d3 to your computer and use it in GitHub Desktop.
Save thursby/d35c5dbc11be9ebaf48bdcbcac3a68d3 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os.path
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.oauth2 import service_account
from google.auth.transport.requests import Request
SCOPES = ['https://www.googleapis.com/auth/spreadsheets']
def logToSpreadsheet(spreadsheet_id, spreadsheet_range, entry):
creds = service_account.Credentials.from_service_account_file(
'service_account.json',
scopes=SCOPES
)
service = build('sheets', 'v4', credentials=creds, cache_discovery=False)
sheet = service.spreadsheets()
result = sheet.values().get(
spreadsheetId=spreadsheet_id,
range=spreadsheet_range
).execute()
list = [entry]
resource = {'majorDimension': 'ROWS', 'values': list}
sheet.values().append(
spreadsheetId=spreadsheet_id,
range=spreadsheet_range,
body=resource,
valueInputOption='USER_ENTERED').execute()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment