prof-rossetti / intro-to-python

An Introduction to Programming in Python
Other
97 stars 244 forks source link

Update gspread Notes #65

Closed s2t2 closed 1 year ago

s2t2 commented 3 years ago

Looks like there have been some changes to the gspread package API. https://gspread.readthedocs.io/en/latest/oauth2.html

We should make sure the existing notes still work, and update them as necessary.

gc = gspread.service_account(filename='path/to/the/downloaded/file.json')

UPDATE: new version of gspread with object oriented approach: https://github.com/prof-rossetti/flask-sheets-template-2023/blob/main/app/spreadsheet_service.py

s2t2 commented 2 years ago

Also, here is the (new) way to easily get user's credentials (colab only):

from google.colab import auth

# asks you to login
auth.authenticate_user()
from google.auth import default

# uses your login credentials
creds, _ = default()
print(creds)
s2t2 commented 2 years ago

NOTE IF YOU HAVE BARCODES / VALUES THAT START WITH ZERO (EDGE CASE)

OK so it looks like the read values function from gspread will numericise all values, so barcodes with leading zeros (like 012000161155 even with leading apostrophe '012000161155) might not work unless we install the new version of gspread, and pass numericize_ignore parameter

In colab:

%%capture

!pip uninstall gspread -y
!pip install gspread --upgrade
# !pip install gspread==5.5.0
# pass a list of ints of indices of the columns (starting at 1)
rows = sheet.get_all_records(numericise_ignore=[1])