fixed all-day calendar entries by manually giving them a time. No clue why that should be needed but better fix it then not
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
from dotenv import load_dotenv
|
||||
from datetime import datetime, timedelta
|
||||
from datetime import datetime, timedelta, date, time
|
||||
|
||||
from zoneinfo import ZoneInfo
|
||||
import caldav, os, random
|
||||
@@ -23,10 +23,17 @@ client = caldav.DAVClient(
|
||||
)
|
||||
calendar = client.calendar(url=CALDAV_URL)
|
||||
|
||||
# we need to convert all-day events from date to daytime (add a time and tz)
|
||||
# dont know when id even need an all day event but better be safe so why not
|
||||
def to_datetime(value):
|
||||
if isinstance(value, date) and not isinstance(value, datetime):
|
||||
value = datetime.combine(value, time.min, tzinfo=TIME_ZONE) # just set time to 00:00
|
||||
return value
|
||||
|
||||
# grab ALL sessions and return as array of dicts
|
||||
def get_all_sessions() -> list:
|
||||
events = calendar.events()
|
||||
events.sort(key=lambda e: e.vobject_instance.vevent.dtstart.value)
|
||||
events.sort(key=lambda e: to_datetime(e.vobject_instance.vevent.dtstart.value))
|
||||
|
||||
event_list = []
|
||||
for event in events:
|
||||
@@ -125,6 +132,13 @@ def get_last_n_days(n: int, sessions) -> list[dict]:
|
||||
|
||||
return days
|
||||
|
||||
# get total of all sessions passed
|
||||
def get_total(sessions) -> int:
|
||||
total_min = 0
|
||||
for session in sessions:
|
||||
total_min += session["minutes"]
|
||||
return total_min
|
||||
|
||||
# get total minutes studying this month
|
||||
def get_total_month(sessions) -> int:
|
||||
total_min = 0
|
||||
@@ -158,7 +172,7 @@ def get_worst_and_best(totals) -> dict:
|
||||
def get_stats(sessions, totals) -> dict:
|
||||
w_and_b = get_worst_and_best(totals)
|
||||
return {
|
||||
"semester":"hi",
|
||||
"semester":round(get_total(sessions)/60, 1),
|
||||
"month":round(get_total_month(sessions)/60, 1),
|
||||
"top_subject":w_and_b["best"],
|
||||
"worst_subject":w_and_b["worst"]
|
||||
|
||||
Reference in New Issue
Block a user