Exemplo n.º 1
0
def Filter(q):
    todos = todotxtio.from_file(todo_path)
    filtered = list()
    for todo in todos:
        if q.lower() in todo.__repr__().lower():
            filtered.append(todo)
    return filtered
Exemplo n.º 2
0
def includeTodo(todoToAdd):
    conf = Configurator()
    list_of_todos = todotxtio.from_file(conf.todo)
    for i in range(len(list_of_todos)):
        list_of_todos[i].tags = getTagsAfterStopIfNeeded(list_of_todos[i])
    list_of_todos.append(todoToAdd)
    todotxtio.to_file(conf.todo, list_of_todos)
Exemplo n.º 3
0
def Del(task):
    todos = todotxtio.from_file(todo_path)
    newtodos = list()
    for todo in todos:
        print(todo.__repr__(), task.__repr__())
        if todo.__repr__() != task.__repr__():
            newtodos.append(todo)
    todotxtio.to_file(todo_path, newtodos)
Exemplo n.º 4
0
def saveTodo(todoToChange):
    conf = Configurator()
    list_of_todos = todotxtio.from_file(conf.todo)
    for i in range(len(list_of_todos)):
        if list_of_todos[i].text == todoToChange.text:
            list_of_todos[i].tags = todoToChange.tags
        else:
            list_of_todos[i].tags = getTagsAfterStopIfNeeded(list_of_todos[i])
    todotxtio.to_file(conf.todo, list_of_todos)
Exemplo n.º 5
0
def toPrio(task, p):
    todos = todotxtio.from_file(todo_path)
    newtodos = list()
    print(task)
    for todo in todos:
        print(todo.__repr__(), task.__repr__())
        if todo.__repr__() == task.__repr__():
            todo.priority = p
        newtodos.append(todo)
    todotxtio.to_file(todo_path, newtodos)
Exemplo n.º 6
0
def toDone(task):
    todos = todotxtio.from_file(todo_path)
    newtodos = list()
    print(task)
    for todo in todos:
        print(todo.__repr__(), task.__repr__())
        if todo.__repr__() == task.__repr__():
            todo.completed = True
        newtodos.append(todo)
    todotxtio.to_file(todo_path, newtodos)
Exemplo n.º 7
0
def handleQuery(query):
    if query.isValid and query.isTriggered:
        if error:
            return error
        if not query.string:
            todos = todotxtio.from_file(todo_path)
            return [
                buildItem(
                    todo,
                    actions=[FuncAction("Done", lambda t=todo: toDone(t)),
                             FuncAction("Delete", lambda t=todo: Del(t))]
                ) for todo in todos]
        else:
            tokens = query.string.split()
            if tokens[0] not in actions:
                return [
                    buildItem(
                        todo,
                        actions=[FuncAction("Done", lambda t=todo: toDone(t)),
                                 FuncAction("Delete", lambda t=todo: Del(t))]
                    ) for todo in Filter(query.string)]
            if tokens[0] == "add":
                del tokens[0]
                if not tokens:
                    return [Item(text="Add a task", icon=iconPath)]
                else:
                    txt = ' '.join(tokens)
                    return [buildNewItem(todotxtio.from_string(txt)[0])]

            elif tokens[0] == "prio":
                del tokens[0]
                if not tokens:
                    return [
                        Item(text="Set the priority of a task", icon=iconPath)
                    ]
                elif len(tokens[0]) == 1 and 90 >= ord(tokens[0]) >= 65:
                    prio = tokens[0]
                    del tokens[0]
                    q = ' '.join(tokens)
                    return [
                        buildItem(
                            t,
                            actions=[
                                FuncAction(f"Set Prio to {prio}",
                                           lambda t=t: toPrio(t, prio))
                            ]
                        ) for t in Filter(q)
                    ]
Exemplo n.º 8
0
    def after_track_time(self, todo, before_started_at, after_started_at,
                         total_time, just_now):
        """
        This event is fired after user click on one task or close the app with a task started
        Take on account that this event is fired per task and one click may fire this event two times:
        one to finalize previous, other for initialize this
        In the original code only track total time per task. To sum all time inverted in a task
        you need to know when started it and with the current time you can sum time to total time
        With this hook you can know when was started and the total time in one step
        Arguments:
        * todo (todo object. See todotxt.io) Object that hold information
        * before_started_at: Unix time. Last started time
        * after_started_at (float): Unix time. If greater than 0 todo has initialized
                                               else the todo has being finalized
        * total_time: Acumulated time in todo
        * just_now: Unix time. Only one time instance accross call's
        """
        if before_started_at:
            list_of_todos = todotxtio.from_file(self.todo_histoy)
            new_todo_history = todotxtio.Todo(text=todo.text)
            new_todo_history.projects = todo.projects
            new_todo_history.contexts = todo.contexts
            new_todo_history.completed = True
            new_todo_history.tags["started"] = str(before_started_at)
            new_todo_history.tags["ended"] = str(just_now)
            new_todo_history.tags["step_time"] = str(just_now -
                                                     before_started_at)
            new_todo_history.tags["total_time"] = str(todo.tags["total_time"])
            list_of_todos.append(new_todo_history)
            todotxtio.to_file(self.todo_histoy, list_of_todos)

        print(
            "todo: {}, before_started_at: {}, after_started_at: {}, total_time: {}, just_now: {}"
            .format(
                todo.text,
                before_started_at,
                after_started_at,
                total_time,
                just_now,
            ))
Exemplo n.º 9
0
def trackHistory(todo, just_now):
    beforeTags = {}
    if todo:
        beforeTags = todo.tags
    started_at = float(beforeTags.get("started_at", 0))
    conf = Configurator()
    list_of_history = todotxtio.from_file(conf.todo_histoy)
    new_todo_history = todotxtio.Todo(text=todo.text)
    new_todo_history.projects = todo.projects
    new_todo_history.contexts = todo.contexts
    new_todo_history.completed = True
    new_todo_history.tags["started"] = str(started_at)
    new_todo_history.tags["ended"] = str(just_now)
    new_todo_history.tags["step_time"] = str(just_now - started_at)
    new_todo_history.tags["total_time"] = str(
        float(todo.tags.get("total_time", 0)) + (just_now - started_at)
    )
    desc = formatTodo(todo.tags.get("description"))
    if desc:
        new_todo_history.tags["description"] = desc
    list_of_history.append(new_todo_history)
    todotxtio.to_file(conf.todo_histoy, list_of_history)
Exemplo n.º 10
0
def main():
    #check if tmp file remains, if so, load it
    if os.path.isfile(TODO_TXT_TMP):
        list_of_todos = tdt.from_file(TODO_TXT_TMP)
        print('Loaded To-Dos from {} !'.format(TODO_TXT_TMP))
    else:
        #generate the main list of To-dos by reading in todo.txt
        list_of_todos = tdt.from_file(TODO_TXT)
    #save timestamped backup of todo.txt content
    backup_name = 'todo_txt_' + re.sub(
        r'\D+', '',
        datetime.now().isoformat(timespec='seconds'))
    #tdt.to_file(backup_name, list_of_todos)
    if os.path.isfile(TODO_TXT):
        os.rename(TODO_TXT, backup_name)
    #give IDs to all To-dos, sort list, save to todo_txt_tmp
    list_of_todos = todo_id(list_of_todos)
    sort_todo_list(list_of_todos)
    tdt.to_file(TODO_TXT_TMP, list_of_todos)
    #    print_list(list_of_todos, completed='Y')
    #define today's list of To-Dos from those that aren't completed
    todays_list = make_todays_list(tdt.search(list_of_todos, completed=False))
    #initialise variables keeping track of Pomos done, their number, time spent
    done_list, pomo_done, time_today = [], 0, 0
    #loop for moving To-dos from today's list to done list by doing them
    while True:
        option_selected = selection(todays_list, "CRSF", default_option='0')
        if option_selected == 'C':
            list_of_todos, todays_list = todo_list_menu_selection(
                list_of_todos, todays_list)
            continue
        elif option_selected == 'F':
            print("That's it for today!")
            break
        elif option_selected == 'R':
            ###############NEED TO SAVE ANYTHING?????????????????????????????
            #re-initialise
            done_list, pomo_done, time_today = [], 0, 0
            #update todays_list by adding from todo.txt
            todays_list = make_todays_list(todays_list, list_of_todos)
            feedback(pomo_done, time_today, done_list, todays_list)
            continue
        elif option_selected == 'S':
            print("not yet implemented")
            continue


#        else: #has to be a To-do
        try:
            completed, pomo_count, pomo_cycle_duration = run_pomo(
                option_selected)
        except:
            print('\n', 80 * '$' + '\n ' + 40 * '#~')
            print(25 * ' ' + 'Pomo run was interrupted !\n' + 40 * '#~', '\n',
                  80 * '$')
            continue
        #run pomodoro and keep track of metrics
        pomo_done += pomo_count
        time_today += pomo_cycle_duration
        #update the to-do that's going through a pomodoro cycle
        update_todo(option_selected, completed, pomo_count,
                    pomo_cycle_duration)
        print('checking:', option_selected)
        #update the temprary todo.txt file
        tdt.to_file(TODO_TXT_TMP, list_of_todos)
        feedback(pomo_done, time_today, done_list, todays_list)
        if completed == "Y":
            print("You just finished:\n {} \n Well done!".format(
                option_selected))
            done_list.append(option_selected)
            todays_list.remove(option_selected)
        feedback(pomo_done, time_today, done_list, todays_list)
    #sort full list, overwrite the temporary todo.txt file
    sort_todo_list(list_of_todos)
    #save final list, overwriting the original
    tdt.to_file(TODO_TXT, list_of_todos)
    if os.path.isfile(TODO_TXT):
        print("saved current To-Dos to {}.".format(TODO_TXT))
    #remove tmp file - otherwise it will be loaded next time
    if os.path.isfile(TODO_TXT_TMP):
        os.remove(TODO_TXT_TMP)
        print("removed {}.".format(TODO_TXT_TMP))
Exemplo n.º 11
0
def Save(task):
    todos = todotxtio.from_file(todo_path)
    todos.append(task)
    todotxtio.to_file(todo_path, todos)
Exemplo n.º 12
0
    def export_history(self, widget):
        widget.set_sensitive(False)
        history_items = todotxtio.from_file(self.todo_histoy)
        history_items.sort(key=lambda todo: (
            sorted(todo.contexts),
            sorted(todo.projects),
            todo.text,
            todo.tags["started"],
        ))
        if history_items:
            f = open(self.export_file, "w")

            with f:
                fnames = [
                    "context",
                    "project",
                    "todo",
                    "description",
                    "started_date",
                    "started_time",
                    "ended_date",
                    "ended_time",
                    "step_time",
                    "accumulated_time",
                    "total_time_after_step",
                ]
                writer = csv.DictWriter(f, fnames)

                writer.writeheader()
                previous_todo = history_items[0].text
                accumulated_time = 0
                for history_item in history_items:
                    started = self.timestam2datetime(
                        history_item.tags["started"])
                    ended = self.timestam2datetime(history_item.tags["ended"])

                    # Localized time
                    step = (self.timestam2datetime(
                        history_item.tags["step_time"]) -
                            self.timestam2datetime(0)).total_seconds()
                    total = (self.timestam2datetime(
                        history_item.tags["total_time"]) -
                             self.timestam2datetime(0)).total_seconds()
                    if previous_todo != history_item.text:
                        accumulated_time = 0
                        previous_todo = history_item.text
                    accumulated_time += step
                    writer.writerow({
                        "context":
                        re.sub("_", " ", history_item.contexts[0])
                        if len(history_item.contexts) else "",
                        "project":
                        re.sub("_", " ", history_item.projects[0])
                        if len(history_item.projects) else "",
                        "todo":
                        history_item.text,
                        "description":
                        re.sub(
                            "_",
                            " ",
                            history_item.tags.get("description", ""),
                        ),
                        "started_date":
                        self.datetime2datestr(started),
                        "started_time":
                        self.datetime2timestr(started),
                        "ended_date":
                        self.datetime2datestr(ended),
                        "ended_time":
                        self.datetime2timestr(ended),
                        "step_time":
                        str(datetime.timedelta(seconds=round(step, 0))),
                        "accumulated_time":
                        str(
                            datetime.timedelta(
                                seconds=round(accumulated_time, 0))),
                        "total_time_after_step":
                        str(datetime.timedelta(seconds=round(total, 0))),
                    })

            if sys.platform.startswith("linux"):
                subprocess.call(["xdg-open", self.export_file])
            else:
                os.startfile(self.export_file)
        else:
            Alert.show_alert("Your history is clean")
        widget.set_sensitive(True)
Exemplo n.º 13
0
 def get_plaindata(self, ):
     return todotxtio.from_file(self.todo_histoy)
Exemplo n.º 14
0
def searchTodo(todoToSearch):
    conf = Configurator()
    list_of_todos = todotxtio.from_file(conf.todo)
    for todo in list_of_todos:
        if todo.text == todoToSearch:
            return todo
Exemplo n.º 15
0
 def retrieve(self, user):
     return todotxtio.from_file(self.config['path'])