fixed issue
This commit is contained in:
parent
4d2732da54
commit
749b2b33ea
1 changed files with 13 additions and 9 deletions
22
main.py
22
main.py
|
|
@ -1,9 +1,8 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
from datetime import datetime
|
||||
from datetime import datetime, date
|
||||
from flask import Flask
|
||||
from caldav import DAVClient, Calendar, Principal, Todo
|
||||
import re
|
||||
import configparser
|
||||
|
||||
|
||||
|
|
@ -14,8 +13,8 @@ def parseConfig() -> tuple[str, str, str, str]:
|
|||
return file.readline().strip()
|
||||
|
||||
config = configparser.ConfigParser()
|
||||
# TODO: option to call the one in test instead or specify one
|
||||
config.read("/etc/calDAVtoCSV/config.ini")
|
||||
# config.read("./calDAVtoCSV/config_test.ini")
|
||||
|
||||
calDavAddress = config.get("calDAV", "address")
|
||||
calDavUsername = config.get("calDAV", "username")
|
||||
|
|
@ -37,16 +36,21 @@ def fetch_10_next_todos_as_csv() -> str:
|
|||
return calendar
|
||||
|
||||
def filter_todos(todos: list[Todo]) -> list[Todo]:
|
||||
def to_date_safe(value):
|
||||
"""Convert datetime or date to a date safely."""
|
||||
if isinstance(value, datetime):
|
||||
return value.date()
|
||||
elif isinstance(value, date):
|
||||
return value
|
||||
else:
|
||||
raise TypeError(f"Expected date or datetime, got {type(value)}")
|
||||
|
||||
today = datetime.today().date()
|
||||
# This bullshit gets the due date and checks if its before today or not, we only want things to du until today
|
||||
return [
|
||||
todo
|
||||
for todo in todos
|
||||
if (
|
||||
match := re.search(
|
||||
r"\d{4}-\d{2}-\d{2}", todo.icalendar_component["due"]
|
||||
)
|
||||
)
|
||||
and datetime.strptime(match.group(), "%Y-%m-%d").date() > today
|
||||
if to_date_safe(todo.icalendar_component["due"].dt) <= today
|
||||
]
|
||||
|
||||
def todos_to_csv(todos: list[Todo]) -> str:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue