Skip to content

Commit

Permalink
able to get gcal events 3 months before and after the current date
Browse files Browse the repository at this point in the history
  • Loading branch information
qianxuege committed Feb 1, 2025
1 parent f9f65ac commit 9bd5175
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions backend/api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from google.oauth2.credentials import Credentials
from google.auth.transport.requests import Request
from googleapiclient.discovery import build
from datetime import timedelta
from datetime import datetime, timedelta

from dotenv import load_dotenv
import os
Expand Down Expand Up @@ -166,13 +166,20 @@ def get_gcal_events():

service = build("calendar", "v3", credentials=credentials)

# Define the reference date
reference_date = datetime.now()

# Calculate three months before and after
time_min = (reference_date - timedelta(days=90)).isoformat() + "Z"
time_max = (reference_date + timedelta(days=90)).isoformat() + "Z"

try:
events_result = (
service.events()
.list(
calendarId="primary",
timeMin="2025-01-10T00:00:00Z", # Replace with your desired time range
maxResults=10,
timeMin=time_min, # 3 months before now
timeMax=time_max, # 3 months from now
singleEvents=True,
orderBy="startTime",
)
Expand Down
Binary file modified backend/dump.rdb
Binary file not shown.

0 comments on commit 9bd5175

Please sign in to comment.