示例#1
0
    def get_activities(self, query=None):
        if not self.source:
            return []

        if self.source == "evo":
            return [
                activity for activity in get_eds_tasks()
                if query is None or activity['name'].startswith(query)
            ]

        elif self.source == "gtg":
            conn = self.__get_gtg_connection()
            if not conn:
                return []

            activities = []

            tasks = []
            try:
                tasks = conn.GetTasks()
            except dbus.exceptions.DBusException:  #TODO too lame to figure out how to connect to the disconnect signal
                self.__gtg_connection = None
                return self.get_activities(query)  # reconnect

            for task in tasks:
                if query is None or task['title'].lower().startswith(query):
                    name = task['title']
                    if len(task['tags']):
                        name = "%s, %s" % (name, " ".join(
                            [tag.replace("@", "#") for tag in task['tags']]))

                    activities.append({"name": name, "category": ""})

            return activities

        elif self.source == "task":
            conn = TaskWarrior()
            if not conn:
                return []

            activities = []
            tasks = []

            task_filter = {'status': 'pending'}
            tasks = conn.filter_tasks(task_filter)

            for task in tasks:
                name = task['description'].replace(",", "")  # replace comma
                category = ""
                if 'tags' in task:
                    name = "%s, %s " % (name, " ".join(task['tags']))

                if 'project' in task:
                    category = task['project']

                activities.append({"name": name, "category": category})

            return activities
示例#2
0
 def update(self, widgets):
     """Return a string with the number of pending tasks from TaskWarrior."""
     try:
         taskrc = self.parameter("taskrc", "~/.taskrc")
         w = TaskWarrior(config_filename=taskrc)
         pending_tasks = w.filter_tasks({'status': 'pending'})
         self._pending_tasks_count = str(len(pending_tasks))
     except:
         self._pending_tasks_count = 'Error'
示例#3
0
 def update(self):
     """Return a string with the number of pending tasks from TaskWarrior."""
     try:
         taskrc = self.parameter("taskrc", "~/.taskrc")
         w = TaskWarrior(config_filename=taskrc)
         pending_tasks = w.filter_tasks({"status": "pending"})
         self.__pending_tasks = str(len(pending_tasks))
     except:
         self.__pending_tasks = "n/a"
示例#4
0
文件: external.py 项目: RoSk0/hamster
    def get_activities(self, query = None):
        if not self.source:
            return []

        if self.source == "evo":
            return [activity for activity in get_eds_tasks()
                         if query is None or activity['name'].startswith(query)]

        elif self.source == "gtg":
            conn = self.__get_gtg_connection()
            if not conn:
                return []

            activities = []

            tasks = []
            try:
                tasks = conn.GetTasks()
            except dbus.exceptions.DBusException:  #TODO too lame to figure out how to connect to the disconnect signal
                self.__gtg_connection = None
                return self.get_activities(query) # reconnect


            for task in tasks:
                if query is None or task['title'].lower().startswith(query):
                    name = task['title']
                    if len(task['tags']):
                        name = "%s, %s" % (name, " ".join([tag.replace("@", "#") for tag in task['tags']]))

                    activities.append({"name": name,
                                       "category": ""})

            return activities

        elif self.source == "task":
            conn = TaskWarrior ()
            if not conn:
                return []

            activities = []
            tasks = []

            task_filter = {'status':'pending'}
            tasks = conn.filter_tasks(task_filter)

            for task in tasks:
                name = task['description'].replace(",","")  # replace comma
                category = ""
                if 'tags' in task:
                    name = "%s, %s " % (name, " ".join(task['tags']))

                if 'project' in task:
                    category = task['project']

                activities.append({"name":name,"category":category})

            return activities
def get_tasks_by_due_date(task_client: TaskWarrior,
                          due_date: date) -> typing.List[task.Task]:
    """
    prints the tasks coming up due on the due_date
    """
    # grab tasks due on due_date
    tasks = task_client.filter_tasks(
        filter_dict={"status":
                     Status.PENDING})  # type: typing.List[typing.Dict]
    return [
        task for task in tasks
        if "due" in task and task.get("due").date() == due_date
    ]
def filter_tasks(
    task_client: TaskWarrior,
    filter_callable: typing.Callable,
    status: str = Status.PENDING,
) -> typing.List[task.Task]:
    """
    Filters the tasks based on the callable passed in.
    """
    tasks = task_client.filter_tasks(filter_dict={"status": status})
    return sorted(
        (task for task in tasks if filter_callable(task)),
        key=lambda x: operator.getitem(x, "urgency"),
        reverse=True,
    )
示例#7
0
 def update(self):
     """Return a string with the number of pending tasks from TaskWarrior."""
     try:
         urgency = -1
         taskrc = self.parameter("taskrc", "~/.taskrc")
         w = TaskWarrior(config_filename=taskrc)
         pending_tasks = w.filter_tasks({"status": "pending"})
         if len(pending_tasks) == 0:
             self.__next_task_description = ""
         for task in pending_tasks:
             if task['urgency'] > urgency:
                 self.__next_task_description = task['description']
                 urgency = task['urgency']
     except:
         self.__next_task_description = "Error, could not load tasks"
def get_completed_tasks(
        task_client: TaskWarrior, start_date: date,
        end_date: typing.Optional[date]) -> typing.List[task.Task]:
    """
    Returns a list of completed tasks between a start and end date
    """
    ret_tasks = []
    logger.debug("Fetching list of completed tasks.")
    completed_tasks = task_client.filter_tasks(
        filter_dict={"status":
                     Status.COMPLETED})  # type: typing.List[typing.Dict]
    for task in completed_tasks:
        # parse completed on
        completed_on = task.get("end")
        # completed on in window, then append
        if all([
                completed_on.date() >= start_date,
                completed_on.date() <= end_date
        ]):
            ret_tasks.append(task)
    return sorted(ret_tasks, key=lambda x: operator.getitem(x, "end"))
示例#9
0
def add_taskwarrior_task(current_balance, tags, priority='M'):
    ''' Add or update the taskwarrior task. If a task with the description given
        in TASK_DESC and the given tags already exists. The task description will be
        updated to the value of the current_balance if changed. Otherwise a new
        task will be added.
    '''

    task_filter = {'tags': tags,
                   'description': TASK_DESC}
    desc = " ".join([TASK_DESC, str(current_balance)])
    tw = TaskWarrior()

    task = tw.filter_tasks(task_filter)
    if task:
        old_desc = task['description']
        old_balance = float(old_desc.split()[-1])
        if current_balance < old_balance:
            task.update({'description': desc,
                         'priority': priority})
            tw.task_update(task)
    else:
        tw.task_add(desc, tags=tags, priority=priority)
示例#10
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import json
from taskw import TaskWarrior

label = '◔'
ret = {
    'name': 'taskwarrior',
    'align': 'left',
    'label': label
}
w = TaskWarrior()

context = w.config["context"]

active = w.filter_tasks({'start.isnt': None})
if active:
    ret['short_text'] = str(active[0]['id'])
    ret['full_text'] = str.format("{0}{1[id]}: {1[description]}", label, active[0])
else:
    ret['short_text'] = ""
    ret['full_text'] = "none"

#if context == 'work':
#  print(json.dumps(ret))

print(json.dumps(ret, ensure_ascii=False))