Skip to content

Commit

Permalink
replace with sheet id w/ better error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mythilytm committed Jul 23, 2024
1 parent 31506c6 commit 9f5b0fe
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/sheetsapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install google-auth google-auth-oauthlib google-auth-httplib2 google-api-python-client gspread
pip install google-auth google-auth-oauthlib google-auth-httplib2 google-api-python-client gspread re
- name: Update Google Sheets
env:
Expand Down
9 changes: 7 additions & 2 deletions update_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json
import sys
import gspread
import re
from google.oauth2.service_account import Credentials
from google.auth.exceptions import GoogleAuthError

Expand All @@ -10,8 +11,12 @@ def main():
# Load credentials from the environment variable
credentials_json = os.getenv('GOOGLE_SHEETS_CREDENTIALS')
sheet_id = os.getenv('GOOGLE_SHEET_ID')
if not credentials_json or not sheet_id:
raise ValueError("No credentials found in environment variable.")
if not credentials_json:
raise ValueError("Credentials JSON not found in environment variable.")
if not sheet_id:
raise ValueError("Sheet ID not found in environment variable.")
if not re.match(r'^[a-zA-Z0-9-_]+$', sheet_id):
raise ValueError("Invalid Google Sheet ID.")

credentials_data = json.loads(credentials_json)
print("Credentials loaded successfully.")
Expand Down

0 comments on commit 9f5b0fe

Please sign in to comment.