Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -230,11 +230,12 @@ def handle_outlook_integration(access_token):
|
|
230 |
else:
|
231 |
st.error("Failed to delete email.")
|
232 |
|
|
|
233 |
def handle_calendar_integration(access_token):
|
234 |
st.subheader("π
Calendar Integration")
|
235 |
st.markdown(f"[Open Calendar]({PRODUCT_SCOPES['π
Calendar']['link']})")
|
236 |
|
237 |
-
#
|
238 |
now = datetime.now()
|
239 |
start_of_month = now.replace(day=1, hour=0, minute=0, second=0, microsecond=0)
|
240 |
end_of_month = start_of_month.replace(month=start_of_month.month % 12 + 1, day=1) - timedelta(days=1)
|
@@ -242,9 +243,28 @@ def handle_calendar_integration(access_token):
|
|
242 |
events = make_api_call(access_token, f"me/calendarView?startDateTime={start_of_month.isoformat()}&endDateTime={end_of_month.isoformat()}&$orderby=start/dateTime")
|
243 |
|
244 |
if events and 'value' in events:
|
245 |
-
#
|
246 |
-
|
247 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
248 |
# Create event
|
249 |
st.write("Add a new event:")
|
250 |
event_subject = st.text_input("Event Subject")
|
|
|
230 |
else:
|
231 |
st.error("Failed to delete email.")
|
232 |
|
233 |
+
|
234 |
def handle_calendar_integration(access_token):
|
235 |
st.subheader("π
Calendar Integration")
|
236 |
st.markdown(f"[Open Calendar]({PRODUCT_SCOPES['π
Calendar']['link']})")
|
237 |
|
238 |
+
# Get the current month's start and end dates
|
239 |
now = datetime.now()
|
240 |
start_of_month = now.replace(day=1, hour=0, minute=0, second=0, microsecond=0)
|
241 |
end_of_month = start_of_month.replace(month=start_of_month.month % 12 + 1, day=1) - timedelta(days=1)
|
|
|
243 |
events = make_api_call(access_token, f"me/calendarView?startDateTime={start_of_month.isoformat()}&endDateTime={end_of_month.isoformat()}&$orderby=start/dateTime")
|
244 |
|
245 |
if events and 'value' in events:
|
246 |
+
# Create a calendar view
|
247 |
+
cal = calendar.monthcalendar(now.year, now.month)
|
248 |
+
st.write(f"Calendar for {now.strftime('%B %Y')}")
|
249 |
+
|
250 |
+
# Create a placeholder for each day
|
251 |
+
day_placeholders = {}
|
252 |
+
for week in cal:
|
253 |
+
cols = st.columns(7)
|
254 |
+
for i, day in enumerate(week):
|
255 |
+
if day != 0:
|
256 |
+
day_placeholders[day] = cols[i].empty()
|
257 |
+
day_placeholders[day].write(f"**{day}**")
|
258 |
+
|
259 |
+
# Populate the calendar with events
|
260 |
+
for event in events['value']:
|
261 |
+
start_date = datetime.fromisoformat(event['start']['dateTime'][:-1]) # Remove 'Z' from the end
|
262 |
+
day = start_date.day
|
263 |
+
if day in day_placeholders:
|
264 |
+
day_placeholders[day].write(f"{start_date.strftime('%H:%M')} - {event['subject']}")
|
265 |
+
else:
|
266 |
+
st.write("No events found or unable to fetch events.")
|
267 |
+
|
268 |
# Create event
|
269 |
st.write("Add a new event:")
|
270 |
event_subject = st.text_input("Event Subject")
|