aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorB. Stack <bgstack15@gmail.com>2023-05-19 09:09:11 -0400
committerB. Stack <bgstack15@gmail.com>2023-05-19 09:09:11 -0400
commitcba32f7fc79f9ca7758d8bff7cbb9202413eadf0 (patch)
tree8d90d14e457185da3d8b7d2ffb7ed0fb24082ac8
parentinitial commit (diff)
downloadagenda-cba32f7fc79f9ca7758d8bff7cbb9202413eadf0.tar.gz
agenda-cba32f7fc79f9ca7758d8bff7cbb9202413eadf0.tar.bz2
agenda-cba32f7fc79f9ca7758d8bff7cbb9202413eadf0.zip
add my own check for event_starts_during_date
-rwxr-xr-xagenda.py28
1 files changed, 24 insertions, 4 deletions
diff --git a/agenda.py b/agenda.py
index fa1fa16..dde1d24 100755
--- a/agenda.py
+++ b/agenda.py
@@ -50,16 +50,34 @@ def print_calendars_demo(calendars):
else:
print("your principal has no calendars")
-def show_event(event):
+def event_starts_during_date(eventdate, thisdate):
+ # eventdate must be a date or datetime
+ # thisdate MUST be date, not datetime
+ happens_on_this_date = False
+ if type(eventdate) == datetime:
+ eventdate = eventdate.date()
+ if eventdate >= thisdate and eventdate < (thisdate + timedelta(days=1)):
+ happens_on_this_date = True
+ #print(f"Checking eventdate {eventdate} to see if it happens on thisdate {thisdate}: {happens_on_this_date}")
+ return happens_on_this_date
+
+def show_event(event,thisdate):
+ # only display event if it is on thisdate.
+ if type(thisdate) == datetime:
+ thisdate = thisdate.date()
+ if type(thisdate) != date:
+ print("Warning! Setting thisdate to today.")
+ thisdate = date.today()
response = ""
all_dtstart_dt = []
all_dtstart_str_dt = []
- #print(event.data)
+ print(event.data)
#for i in event.icalendar_component:
# print(f"{i} IS {event.icalendar_component[i]}")
dtstart = event.icalendar_component["DTSTART"]
dtstart_dt = dtstart and dtstart.dt
- if str(dtstart_dt) not in all_dtstart_str_dt:
+ if str(dtstart_dt) not in all_dtstart_str_dt and event_starts_during_date(dtstart_dt, thisdate):
+ #print(f"Event dtstart_dt is {dtstart_dt}")
all_dtstart_dt.append(dtstart_dt)
all_dtstart_str_dt.append(str(dtstart_dt))
if all_dtstart_dt:
@@ -151,6 +169,7 @@ def summarize_calendar(calendar, thisdate = None, count = 0):
# so now, thisdate should be of type datetime.date
d = thisdate
d2 = d + timedelta(days=1)
+ #print(f"Using d {d} and d2 {d2}")
year, month, day = d2.year, d2.month, d2.day
events_fetched = calendar.search(
start=d,
@@ -159,6 +178,7 @@ def summarize_calendar(calendar, thisdate = None, count = 0):
expand=True,
)
x = 0
+ events_fetched = [i for i in events_fetched if event_starts_during_date(i.icalendar_component["DTSTART"].dt,d)]
events_wholeday = [i for i in events_fetched if type(i.icalendar_component["DTSTART"].dt) == date]
events_regular = [i for i in events_fetched if type(i.icalendar_component["DTSTART"].dt) != date]
events_sorted = sorted(events_regular, key=event_key)
@@ -173,7 +193,7 @@ def summarize_calendar(calendar, thisdate = None, count = 0):
h2_text_color = get_text_color_based_on_background_color(color,"#ffffff","#000000")
text_color = get_text_color_based_on_background_color(color2,"#ffffff","#000000")
response += f"<div style='background-color: {color2}; color: {text_color}'><h2 style='background-color: {color}; color: {h2_text_color}'>{calendar.name}</h2>\n"
- response += show_event(i)
+ response += show_event(i,thisdate)
if x > 0:
response += "</div>\n"
return response
bgstack15