-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathforms.py
More file actions
42 lines (32 loc) · 1.2 KB
/
forms.py
File metadata and controls
42 lines (32 loc) · 1.2 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
import json
from typing import Any
from googleapiclient.discovery import build
from google.oauth2 import service_account
import create_config_json as cfig_creator
sheet: Any = None
try:
with open('config.json', 'r') as cfig:
cfig_dict = json.loads(cfig.read())
SERVICE_ACCOUNT_FILE = cfig_dict['SERVICE_ACCOUNT_FILE']
# Spread Sheet Id
ss_ID = cfig_dict['ss_ID']
except FileNotFoundError:
cfig_creator.main()
with open('config.json', 'r') as cfig:
cfig_dict = json.loads(cfig.read())
SERVICE_ACCOUNT_FILE = cfig_dict['SERVICE_ACCOUNT_FILE']
# Spread Sheet Id
ss_ID = cfig_dict['ss_ID']
def setup() -> None:
global sheet
SCOPES = ['https://www.googleapis.com/auth/spreadsheets']
creds = service_account.Credentials.from_service_account_file(
SERVICE_ACCOUNT_FILE, scopes=SCOPES)
service = build('sheets', 'v4', credentials=creds)
sheet = service.spreadsheets()
def get_spreadsheet_rows() -> dict:
result = sheet.values().get(spreadsheetId=ss_ID,
range="Form Responses 1!A1:I1000000").execute()
# print('\n\n' + str(result) + '\n\n')
return result['values'][1:]
setup()