81 lines
3.6 KiB
Python
Executable file
81 lines
3.6 KiB
Python
Executable file
#! /usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""Todo.txt interface for `argos <https://github.com/p-e-w/argos>`."""
|
|
|
|
# <bitbar.title>todo</bitbar.title>
|
|
# <bitbar.version>v1.0</bitbar.version>
|
|
# <bitbar.author>Tobias Schmidl</bitbar.author>
|
|
# <bitbar.author.github>schtobia</bitbar.author.github>
|
|
# <bitbar.desc>Todo.txt interface</bitbar.desc>
|
|
# <bitbar.image></bitbar.image>
|
|
# <bitbar.dependencies>python,todotxtio</bitbar.dependencies>
|
|
# <bitbar.abouturl>https://gitlab.com/schtobia/argos-todo/blob/master/todo.py</bitbar.abouturl>
|
|
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
import todotxtio # type: ignore
|
|
|
|
__author__ = "Tobias Schmidl"
|
|
__copyright__ = "Copyright 2021, Tobias Schmidl"
|
|
__license__ = "MIT"
|
|
__version__ = "1.0"
|
|
__maintainer__ = "Tobias Schmidl"
|
|
|
|
TODO_TXT_PATH = Path.home() / '.todo-txt' / 'todo.txt'
|
|
COLOR_LIST = {
|
|
1: ['#fc8d59'],
|
|
2: ['#fc8d59', '#91cf60'],
|
|
3: ['#fc8d59', '#ffffbf', '#91cf60'],
|
|
4: ['#d7191c', '#fdae61', '#a6d96a', '#1a9641'],
|
|
5: ['#d7191c', '#fdae61', '#ffffbf', '#a6d96a', '#1a9641'],
|
|
6: ['#d73027', '#fc8d59', '#fee08b', '#d9ef8b', '#91cf60', '#1a9850'],
|
|
7: ['#d73027', '#fc8d59', '#fee08b', '#ffffbf', '#d9ef8b', '#91cf60', '#1a9850'],
|
|
8: ['#d73027', '#f46d43', '#fdae61', '#fee08b', '#d9ef8b', '#a6d96a', '#66bd63', '#1a9850'],
|
|
9: ['#d73027', '#f46d43', '#fdae61', '#fee08b', '#ffffbf', '#d9ef8b', '#a6d96a', '#66bd63', '#1a9850'],
|
|
10: ['#a50026', '#d73027', '#f46d43', '#fdae61', '#fee08b', '#d9ef8b', '#a6d96a', '#66bd63', '#1a9850', '#006837'],
|
|
11: [
|
|
'#a50026', '#d73027', '#f46d43', '#fdae61', '#fee08b', '#ffffbf', '#d9ef8b', '#a6d96a', '#66bd63', '#1a9850',
|
|
'#006837'
|
|
]
|
|
}
|
|
|
|
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 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)
|
|
priority = int(((priority - min_prio) * new_range) / old_range)
|
|
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]))
|
|
other_tags = [key + ": " + value for key, value in task.tags.items() if key != "due"]
|
|
if other_tags:
|
|
print("--", " ".join(other_tags))
|