Skip to content

Commit

Permalink
add error handling 2
Browse files Browse the repository at this point in the history
  • Loading branch information
mythilytm committed Jul 23, 2024
1 parent 7aef3ad commit 1c6f1f3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/sheetsapi.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# update google sheets
name: Update Google Sheets

on:
Expand Down Expand Up @@ -28,5 +27,6 @@ jobs:
- name: Update Google Sheets
env:
GOOGLE_SHEETS_CREDENTIALS: ${{ secrets.GOOGLE_SHEETS_CREDENTIALS }}
run: echo "${GOOGLE_SHEETS_CREDENTIALS}" > credentials.json
python update_matrix.py
run: |
echo "${GOOGLE_SHEETS_CREDENTIALS}" > credentials.json
python update_matrix.py
5 changes: 5 additions & 0 deletions update_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,27 @@ def main():
raise ValueError("No credentials found in environment variable.")

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

# Define the scope and credentials
scopes = [
'https://www.googleapis.com/auth/spreadsheets',
'https://www.googleapis.com/auth/drive'
]
credentials = Credentials.from_service_account_info(credentials_data, scopes=scopes)
print("Credentials initialized successfully.")

# Initialize the client
client = gspread.authorize(credentials)
print("Google Sheets client authorized successfully.")

# Open the Google Sheet by name
sheet = client.open("Product Matrices").worksheet("Deployment Matrix")
print("Google Sheet opened successfully.")

# Update the sheets
update_response = sheet.update('B2', 'Hello, sheet!')
print("Sheet update response:", update_response)

# Verify update response
if not update_response:
Expand Down

0 comments on commit 1c6f1f3

Please sign in to comment.