GothenburgBitFactory / tasklib

A Python library for interacting with taskwarrior databases.
http://tasklib.readthedocs.org/en/latest/
BSD 3-Clause "New" or "Revised" License
147 stars 27 forks source link

tasklib should respect context or support it as an option IMO #133

Open 5balls opened 3 weeks ago

5balls commented 3 weeks ago

I think context should be supported.

As a workaround I have code similar to this:

from tasklib import TaskWarrior

tw = TaskWarrior(data_location='~/.task')

context = tw.execute_command(["_get","rc.context"])[0]

if context:
  context_read = tw.execute_command(["_get","rc.context." + context + ".read"])[0]
  context_filter = '+PENDING and ( ' + context_read + ')'
  nexttasks = tw.tasks.filter(context_filter)
else:
  nexttasks = tw.tasks.pending()
5balls commented 3 weeks ago

As a side remark:

tw.tasks.pending().filter(context_filter)

would not work as it does not do an and operation but an or operation instead - not what I would expect.