Sort todo list by creation date
This commit is contained in:
parent
b80af75c09
commit
c233d8fb02
1 changed files with 12 additions and 4 deletions
|
|
@ -24,6 +24,15 @@ BASE_URL = os.getenv('CALDAV_URL')
|
|||
NEXT_DAYS = int(os.getenv('NEXT_DAYS'))
|
||||
|
||||
|
||||
def _date_to_datetime(d):
|
||||
if isinstance(d, datetime):
|
||||
return d
|
||||
elif isinstance(d, date):
|
||||
return datetime.combine(d, time(0, 0)).replace(tzinfo=timezone.utc)
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
def fill_event(component, calendar) -> dict[str, str]:
|
||||
# quite some data is tossed away here - like, the recurring rule.
|
||||
cur = {}
|
||||
|
|
@ -34,10 +43,7 @@ def fill_event(component, calendar) -> dict[str, str]:
|
|||
# It's one of the most confusing date formats ever!
|
||||
# Use year-month-day time instead ... https://xkcd.com/1179/
|
||||
cur["start"] = component.start.strftime("%d/%m/%Y %H:%M")
|
||||
if isinstance(component.start, datetime):
|
||||
cur["dstart"] = component.start
|
||||
else:
|
||||
cur["dstart"] = datetime.combine(component.start, time(0, 0)).replace(tzinfo=timezone.utc)
|
||||
cur["dstart"] = _date_to_datetime(component.start)
|
||||
endDate = component.end
|
||||
if endDate:
|
||||
cur["end"] = endDate.strftime("%m/%d/%Y %H:%M")
|
||||
|
|
@ -47,6 +53,7 @@ def fill_event(component, calendar) -> dict[str, str]:
|
|||
def fill_todo(component, calendar) -> dict[str, str]:
|
||||
cur = {}
|
||||
cur["calendar"] = f"{calendar}"
|
||||
cur["dstart"] = _date_to_datetime(component.get("dtstamp").dt)
|
||||
cur["summary"] = component.get("summary")
|
||||
cur["description"] = component.get("description")
|
||||
return cur
|
||||
|
|
@ -92,6 +99,7 @@ def main():
|
|||
for event in event_list:
|
||||
display_event(event)
|
||||
|
||||
todo_list = sorted(todo_list, key=lambda x: x['dstart'])
|
||||
for todo in todo_list:
|
||||
display_todo(todo)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue