Created
June 21, 2019 18:46
-
-
Save thursby/d35c5dbc11be9ebaf48bdcbcac3a68d3 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
#!/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