Exemplo n.º 1
0
    def _recalc(self):
        self._todos = defaultdict(list)
        todo_dir = os.path.dirname(self.filename)
        todo_filenames = glob(todo_dir + "/*.txt")
        for fn in todo_filenames:
            bfn = os.path.basename(fn)
            tf = TODOFile(fn)
            for project_name, project_todos in tf.projects.items():
                p = self._projects.setdefault(project_name,
                                              Project(project_name))
                p.add_todos(bfn, project_todos)

            op = self._projects.setdefault(self.orphan_projectname,
                                          Project(self.orphan_projectname,
                                                  "Todos with no project"))
            op.add_todos(bfn, [t for t in tf.get_todos()
                               if len(t.projects) == 0])
Exemplo n.º 2
0
    return d

if __name__ == '__main__':
    # todo.sh usage:
    if len(sys.argv) > 1 and sys.argv[1] == 'usage':
        print("USAGE: ...")
        sys.exit()

    parser = argparse.ArgumentParser(description='todotxt archive script')
    parser.add_argument('--dir', default=os.environ.get('TODO_DIR', '.'),
                        help="Directory to look for todo.txt files")
    parser.add_argument("--days", default=7, type=int,
                        help="Number of days in the past to recap")
    opts = parser.parse_args()

    done_file = TODOFile(os.path.join(opts.dir, "done.txt"))

    todos_by_done_date = todos_grouped_by(done_file.get_todos(),
                                          'done_date')

    for date in sorted(todos_by_done_date.keys())[-opts.days:]:
        todos = todos_by_done_date[date]
        d = datetime.strptime(date, DATE_FMT)
        ds = datetime.strftime(d, "%A, %B %d: ")
        print(ds + "{} completed todos".format(len(todos)))
        print(80 * "-")
        if len(todos) == 0:
            continue

        todos_by_hour = defaultdict(list)
        for t in todos:
Exemplo n.º 3
0
from todotxt import TODOFile, DATE_FMT, todo_from_line

if __name__ == "__main__":
    # todo.sh usage:
    if len(sys.argv) > 1 and sys.argv[1] == "usage":
        print("USAGE: ...")
        sys.exit()

    parser = argparse.ArgumentParser(description="todotxt 'ADD' script")
    parser.add_argument("--dir", default=os.environ.get("TODO_DIR", "."), help="Directory to look for todo.txt files")
    parser.add_argument("-f", dest="fnpat", default="todo.txt", help="filename prefix to save to")
    parser.add_argument("text", nargs=argparse.REMAINDER, help="text of new todo")

    opts = parser.parse_args()

    if opts.fnpat.endswith(".txt"):
        wildcard = ""
    else:
        wildcard = "*.txt"
    fnl = glob(os.path.join(opts.dir, "{}{}".format(opts.fnpat, wildcard)))
    if len(fnl) > 1:
        print("Too many matches for -f: {}".format(", ".join(fnl)))
        sys.exit(1)

    todo_file = TODOFile(fnl[0])

    t = todo_from_line(" ".join(opts.text))
    t.set_created_now()
    todo_file.add_todo(t)
    todo_file.save()
Exemplo n.º 4
0
if __name__ == "__main__":
    # todo.sh usage:
    if len(sys.argv) > 1 and sys.argv[1] == "usage":
        print("USAGE: ...")
        sys.exit()

    parser = argparse.ArgumentParser(description="todotxt 'DO' script")
    parser.add_argument("--dir", default=os.environ.get("TODO_DIR", "."), help="Directory to look for todo.txt files")
    parser.add_argument(
        "N", type=int, nargs="*", metavar="line number(s)", help="line numbers of todos to edit (starting at 1)"
    )

    opts = parser.parse_args()

    todo_file = TODOFile(os.path.join(opts.dir, "todo.txt"))

    todos = todo_file.get_todos()

    for N in opts.N:
        num = N - 1
        if num > len(todos):
            print("Error: there are only {} todos in {}".format(len(todos), filename))
            print("they are: \n{}".format(list(map(str, f.get_todos()))))
            sys.exit(1)

        t = todos[num]
        if t.done:
            print("Already done!")
            sys.exit()
Exemplo n.º 5
0
if __name__ == '__main__':

    # todo.sh usage:
    if len(sys.argv) > 1 and sys.argv[1] == 'usage':
        print("USAGE: archive --dir=todo_dir")
        sys.exit()

    parser = argparse.ArgumentParser(description='todotxt archive script')
    parser.add_argument('--dir', default=os.environ.get('TODO_DIR', '.'),
                        help="Directory to look for todo.txt files")

    opts = parser.parse_args()
    print("Archiving in {}".format(opts.dir))
    todo_files = glob(opts.dir + "/*.txt")
    done_file = TODOFile(os.path.join(opts.dir, "done.txt"))
    for fn in todo_files:
        bfn = os.path.basename(fn)
        if bfn == "done.txt":
            continue
        f = TODOFile(fn)
        print("{:<18}: ".format(bfn), end="")
        archived = 0
        to_delete = []
        for todo in f.get_todos():
            if not todo.done:
                continue
            done_file.add_todo(todo)
            to_delete.append(todo)
            archived += 1
        for deltodo in to_delete:
Exemplo n.º 6
0
    # todo.sh usage:
    if len(sys.argv) > 1 and sys.argv[1] == 'usage':
        print("USAGE: ...")
        sys.exit()


    parser = argparse.ArgumentParser(description='todotxt single edit script')
    parser.add_argument('--dir', default=os.environ.get('TODO_DIR', '.'),
                        help="Directory to look for todo.txt files")
    parser.add_argument('--filename', default='todo.txt',
                        help="Which file to edit")
    parser.add_argument("N", type=int,
                        metavar='line number',
                        help="line number of todo to edit (starting at 1)")
    opts = parser.parse_args()

    filename = os.path.join(opts.dir, opts.filename)
    
    f = TODOFile(filename)
    todos = f.get_todos()

    num = opts.N - 1
    if num > len(todos):
        print("Error: there are only {} todos in {}".format(len(todos),
                                                            filename))
        print("they are: \n{}".format(list(map(str, f.get_todos()))))
        sys.exit(1)
        
    do_edit(todos[num], f)