#!/usr/bin/env python from datetime import date import os import sys from airium import Airium from pytodotxt import TodoTxtParser today = date.today() a = Airium() a('') file = sys.argv[1] if file == '-': file = sys.stdin filename = sys.argv[2] else: filename = os.path.basename(file) tasks = TodoTxtParser().parse(file) def get_date_attribute(t, a): if a in t.attributes: return date.fromisoformat(t.attributes[a][0]) return None def get_due_date(t): return get_date_attribute(t, 'due') or date.max def get_sort_key(t): return str(get_due_date(t)) + '--' + (t.priority or 'ZZ') with a.html(): with a.head(): a.meta(charset="utf-8") a.title(_t="%s - TODO list" % filename) a.meta(name="viewport", content="width=device-width, initial-scale=1") a.link(href="todo.css", rel="stylesheet") with a.body(): with a.div(klass='filters'): with a.label(): a.input(type="checkbox", id='show_completed') a('Show Completed Tasks') with a.label(): a.input(type="checkbox", id='show_future') a('Show Future Tasks') with a.div(klass='todo_list').ul(): for task in sorted(tasks, key=get_sort_key): threshold = get_date_attribute(task, 't') or date.min threshold_in_future = threshold > today overdue = not task.is_completed and get_due_date(task) < today due_today = not task.is_completed and get_due_date(task) == today classes = [] if task.is_completed: classes.append('completed') if overdue: classes.append('overdue') if due_today: classes.append('due_today') if threshold_in_future: classes.append('threshold_in_future') priority = None if task.priority: classes.append('priority_' + task.priority) priority = task.priority with (a.li(klass=str.join(' ', classes)) if len(classes) > 0 else a.li()): if priority: a.span(_t=priority, klass="priority") a.span(_t=task.description, klass="description") print(a)