Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
cs1-24fa
project04
Commits
d5b02d42
Commit
d5b02d42
authored
8 months ago
by
Adam Blank
Browse files
Options
Download
Email Patches
Plain Diff
Update sheets_api.py
parent
ca70eebc
master
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
support/sheets_api.py
+14
-11
support/sheets_api.py
with
14 additions
and
11 deletions
+14
-11
support/sheets_api.py
View file @
d5b02d42
...
...
@@ -4,17 +4,21 @@ Functionality from Google Sheets API to get and update values in a spreadsheet.
Also creates list of dictionaries representing the pendula in the Newton's cradle.
"""
from
sys
import
exit
from
typing
import
Any
import
sys
import
os
sys
.
path
.
insert
(
0
,
os
.
getcwd
())
from
googleapiclient.errors
import
HttpError
from
googleapiclient.discovery
import
build
from
support.types
import
PendAttrs
from
src.constants
import
RANGE
,
SPREADSHEET_ID
import
termcolor
from
google.oauth2.service_account
import
Credentials
from
googleapiclient.discovery
import
build
from
googleapiclient.errors
import
HttpError
from
typing
import
Any
from
sys
import
exit
import
termcolor
from
src.constants
import
RANGE
,
SPREADSHEET_ID
from
support.types
import
PendAttrs
####
SERVICE_ACCOUNT_FILE
=
"./config.json"
...
...
@@ -22,14 +26,14 @@ SCOPES = ["https://www.googleapis.com/auth/spreadsheets"]
try
:
creds
=
Credentials
.
from_service_account_file
(
SERVICE_ACCOUNT_FILE
,
scopes
=
SCOPES
)
except
Exception
:
except
Exception
as
e
:
print
(
termcolor
.
colored
(
"Please follow the instructions to get your config.json file here:"
,
"red"
)
)
print
(
termcolor
.
colored
(
" https://cs1.caltech.codes/24fa/projects/04/service_account_instructions"
,
color
=
"blue"
))
exit
(
1
)
raise
e
def
get_values
(
spreadsheet_id
:
str
,
range_names
:
str
|
list
[
str
])
->
dict
[
str
,
Any
]:
...
...
@@ -64,8 +68,7 @@ def get_values(spreadsheet_id: str, range_names: str | list[str]) -> dict[str, A
"You can control/cmd + click on the links to go to that line."
,
"red"
))
raise
# exit(1)
raise
e
def
update_values
(
spreadsheet_id
:
str
,
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help