Update app/agent/google_calendar.py
Browse files- app/agent/google_calendar.py +7 -10
app/agent/google_calendar.py
CHANGED
|
@@ -11,27 +11,24 @@ import json
|
|
| 11 |
# Load environment variables from .env file
|
| 12 |
load_dotenv()
|
| 13 |
|
|
|
|
| 14 |
# --- Configuration ---
|
| 15 |
creds_str = os.getenv("GOOGLE_CREDS")
|
| 16 |
creds_dict = json.loads(creds_str)
|
| 17 |
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
CALENDAR_ID = os.getenv('GOOGLE_CALENDAR_ID')
|
| 20 |
|
| 21 |
# --- Google Calendar API Setup ---
|
| 22 |
-
SCOPES = ['https://www.googleapis.com/auth/calendar']
|
| 23 |
-
|
| 24 |
def get_calendar_service():
|
| 25 |
"""Initializes and returns the Google Calendar service object."""
|
| 26 |
try:
|
| 27 |
-
|
| 28 |
-
SERVICE_ACCOUNT_CREDENTIAL, scopes=SCOPES)
|
| 29 |
-
service = build('calendar', 'v3', credentials=creds)
|
| 30 |
return service
|
| 31 |
-
except FileNotFoundError:
|
| 32 |
-
print(f"Error: The service account key file '{SERVICE_ACCOUNT_CREDENTIAL}' was not found.")
|
| 33 |
-
print("Please make sure the GOOGLE_SERVICE_ACCOUNT_FILE environment variable is set correctly.")
|
| 34 |
-
return None
|
| 35 |
except Exception as e:
|
| 36 |
print(f"An error occurred during authentication: {e}")
|
| 37 |
return None
|
|
|
|
| 11 |
# Load environment variables from .env file
|
| 12 |
load_dotenv()
|
| 13 |
|
| 14 |
+
|
| 15 |
# --- Configuration ---
|
| 16 |
creds_str = os.getenv("GOOGLE_CREDS")
|
| 17 |
creds_dict = json.loads(creds_str)
|
| 18 |
|
| 19 |
+
# Create credentials directly from dict
|
| 20 |
+
SCOPES = ['https://www.googleapis.com/auth/calendar']
|
| 21 |
+
SERVICE_ACCOUNT_CREDENTIAL = service_account.Credentials.from_service_account_info(
|
| 22 |
+
creds_dict, scopes=SCOPES
|
| 23 |
+
)
|
| 24 |
CALENDAR_ID = os.getenv('GOOGLE_CALENDAR_ID')
|
| 25 |
|
| 26 |
# --- Google Calendar API Setup ---
|
|
|
|
|
|
|
| 27 |
def get_calendar_service():
|
| 28 |
"""Initializes and returns the Google Calendar service object."""
|
| 29 |
try:
|
| 30 |
+
service = build('calendar', 'v3', credentials=SERVICE_ACCOUNT_CREDENTIAL)
|
|
|
|
|
|
|
| 31 |
return service
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
except Exception as e:
|
| 33 |
print(f"An error occurred during authentication: {e}")
|
| 34 |
return None
|