do a conditional writing for each task

we're _much_ more flexible this way.
This commit is contained in:
Tobias Schmidl 2021-05-05 15:09:53 +02:00
parent e1e5fe38b9
commit df7980c6b5

42
todo.py
View file

@ -44,25 +44,37 @@ COLOR_LIST = {
if __name__ == "__main__":
list_of_tasks = todotxtio.from_file(TODO_TXT_PATH)
list_of_priorities = [int(x.priority, base=16) for x in list_of_tasks]
max_prio = max(list_of_priorities)
min_prio = min(list_of_priorities)
list_of_priorities = [int(x.priority, base=16) for x in list_of_tasks if x.priority and x.priority.isalnum()]
max_prio = max(list_of_priorities) if list_of_priorities else 1
min_prio = min(list_of_priorities) if list_of_priorities else 1
new_range = len(set(list_of_priorities)) if list_of_priorities else 1
old_range = max_prio - min_prio + 1
default_priority = int((max_prio - min_prio) * new_range / old_range)
print("📋", len(list_of_tasks))
print("---")
for task in list_of_tasks:
text = "" # pylint: disable=C0103
text_color = COLOR_LIST[new_range][default_priority]
if task.priority:
priority = int(task.priority, base=16)
old_range = max_prio - min_prio + 1
new_range = len(set(list_of_priorities))
priority = int(((priority - min_prio) * new_range) / old_range)
if "due" not in task.tags:
print("<span size=\"larger\" weight=\"bold\">" + task.priority +
"</span>: <span size=\"medium\" foreground=\"" + COLOR_LIST[new_range][priority] + "\">" + task.text +
"</span>")
else:
print("<span size=\"larger\" weight=\"bold\">" + task.priority +
"</span>: <span size=\"medium\" background=\"white\" foreground=\"black\">" + task.tags["due"] +
"</span> <span size=\"medium\" foreground=\"" + COLOR_LIST[new_range][priority] + "\">" + task.text +
"</span>")
text = text + """<span size="larger" weight="bold">""" + task.priority + "</span>: "
text_color = COLOR_LIST[new_range][priority]
text += """<span size="medium" foreground=\"""" + text_color + "\">" + task.text + "</span>"
if "due" in task.tags:
from datetime import datetime
due_date = datetime.strptime(task.tags["due"], "%Y-%m-%d")
now = datetime.now()
tomorrow = datetime(year=now.year, month=now.month, day=now.day + 1)
text += " <span size=\"medium\""
if due_date < tomorrow:
text += """ foreground="white" background="red" weight="bold\""""
text += ">due:" + task.tags["due"] + "</span>"
print(text)
if task.contexts:
print("--", " ".join(["@" + x for x in task.contexts]))
if task.projects:
print("--", " ".join(["+" + x for x in task.projects]))
print("--", " ".join([key + ": " + value for key, value in task.tags.items() if key != "due"]))
other_tags = [key + ": " + value for key, value in task.tags.items() if key != "due"]
if other_tags:
print("--", " ".join(other_tags))