-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsheet_writer.py
28 lines (24 loc) · 972 Bytes
/
sheet_writer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import gspread
from oauth2client.service_account import ServiceAccountCredentials
from gspread.exceptions import CellNotFound
import json
# use creds to create a cl xient to interact with the Google Drive API
scope = ['https://spreadsheets.google.com/feeds',
'https://www.googleapis.com/auth/drive']
creds = ServiceAccountCredentials.from_json_keyfile_name('client_secret.json', scope)
client = gspread.authorize(creds)
# SHEET_NAME = 'Menora Mivtahim - Events - test'
SHEET_NAME = 'Menora Mivtahim - Events'
def _parse_event(event):
return list(reversed(list(event.values())))
def write_to_sheet(event):
sheet = client.open(SHEET_NAME).sheet1
# Extract and print all of the values
try:
sheet.find(event['datetime'])
print("The event already been recorded")
return
except CellNotFound:
print("Adding new event")
event = _parse_event(event)
sheet.append_row(event, value_input_option='RAW')