-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathappendToSheet.py
More file actions
30 lines (21 loc) · 985 Bytes
/
appendToSheet.py
File metadata and controls
30 lines (21 loc) · 985 Bytes
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
29
30
from googleapiclient.discovery import build
from authenticate import *
def appendData(keyToSheet,data):
try:
# Authenticating with googleapiclient
creds = authenticate()
service = build('sheets', 'v4', credentials=creds)
body = {
'values': data.values.tolist()
}
range_name = "Sheet1"
# Appending data to exesting spreadsheet
result = service.spreadsheets().values().append(spreadsheetId=keyToSheet,
range=range_name,
valueInputOption='RAW',
body=body).execute()
# print(result)
return "Data Added successfully"
except HttpError as error:
print(f"An error occurred: {error}")
return "An error occurred"