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])
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: todos_by_hour[t.done_datetime.hour].append(t)
# 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() t.done = True print("done: {}".format(str(t)))
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: f.delete_todo(deltodo) try: done_file.save() f.save() except: print("error saving.") sys.exit(1) print("archived {} todos.".format(archived))
# 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)