def finish(id): with DBConn() as c: c.execute("UPDATE task SET finished = ? WHERE id = ?;", (datetime.datetime.utcnow(), id)) rm_tag(c, "started", id) rm_tag(c, "open", id) add_tag(c, "closed", id) print_tasks(c, [id])
def add(description, priority=None, tags=None): with DBConn() as c: id = c.execute( "INSERT INTO task VALUES (null, ?, ?, ?, NULL, NULL);", (description, priority, datetime.datetime.utcnow()) ).lastrowid for tag in tags + ["open"]: add_tag(c, tag, id) print_tasks(c, [id])
def edit(id): with DBConn() as c: description, = c.execute("SELECT description FROM task WHERE id = ?;", (id,)).fetchone() filename = "/tmp/.mut_edit_%s" % id with open(filename, "w") as fp: fp.write(description) subprocess.call("${EDITOR:-nano} %s" % filename, shell=True) with open(filename, "r") as fp: description = fp.read().strip() c.execute("UPDATE task SET description = ? WHERE id = ?;", (description, id)) print_tasks(c, [id])
def ls(tags=None, neg_tags=None): with DBConn() as c: query = """ SELECT id FROM task WHERE 1=1 """ params = [] for tag, include in [(tag, True) for tag in tags] + [(tag, False) for tag in neg_tags]: query += """ AND ? %s IN (SELECT tag.tag FROM tag WHERE tag.task_id = task.id) """ % ( "" if include else "NOT" ) params.append(tag) query += "ORDER BY priority ASC, id ASC;" task_ids = [id for id, in c.execute(query, params).fetchall()] print_tasks(c, task_ids)
def lis(args): if len(args) == 2: return print_tasks(query_date(date.today()).split("\n")[:-1]) else: atributes = { "-d": list_with_date, "-w":list_last_week, "-lw":list_last_week, } return atributes.get(args[2], "wrong attribute. check help for help...")(args)
def stop(id): with DBConn() as c: rm_tag(c, "started", id) print_tasks(c, [id])
def start(id): with DBConn() as c: c.execute("UPDATE task SET started = ? WHERE id = ?;", (datetime.datetime.utcnow(), id)) add_tag(c, "started", id) print_tasks(c, [id])
def print_ndone_tasks(): ndone_tasks = query_done("n").split("\n")[:-1] x = {} x = print_tasks(tasks=ndone_tasks, task_id_dict=x) return x