Add idea parsing for jrnl file
This commit is contained in:
parent
787a24c6dc
commit
c6cb3dd6c3
3 changed files with 84 additions and 5 deletions
49
README.md
49
README.md
|
@ -12,13 +12,52 @@ More specifically, it:
|
||||||
(marked with an empty `[ ] ` at the beginning of their line)
|
(marked with an empty `[ ] ` at the beginning of their line)
|
||||||
* adds an entry for today's date if none exists yet and populates it with due/overdue tasks from `taskwarrior`
|
* adds an entry for today's date if none exists yet and populates it with due/overdue tasks from `taskwarrior`
|
||||||
|
|
||||||
|
To accomplish this it borrows a little from the [todo.txt](http://todotxt.org/) syntax ---
|
||||||
|
namely the idea of (A) (B) (C) prioritization and `x task done syntax`
|
||||||
|
(i.e. starting a line with `x ` or `[x] ` means it represents an accomplished task).
|
||||||
|
|
||||||
All three of these operations *only* operate on entries which are marked with a special title (`todotxt` by default),
|
All three of these operations *only* operate on entries which are marked with a special title (`todotxt` by default),
|
||||||
though this can be changed through a regex option.
|
though this can be changed through a regex option.
|
||||||
That means, it is also entirely possible to have other entries (with the same date) which will simply be ignored by the script.
|
That means, it is also entirely possible to have other entries (with the same date) which will simply be ignored by the script.
|
||||||
|
|
||||||
To accomplish this it borrows a little from the [todo.txt](http://todotxt.org/) syntax ---
|
Lastly, it transfers what I call 'ideas' to `taskwarrior`.
|
||||||
namely the idea of (A) (B) (C) prioritization and `x task done syntax`
|
These are small tidbits and notions I jot down during the day (hence, 'ideas')
|
||||||
(i.e. starting a line with `x ` or `[x] ` means it represents an accomplished task).
|
and marked as such by starting the line either with `idea: ` or the `taskwarrior` equivalent `+idea `.
|
||||||
|
I want them transferred to `taskwarrior` so they don't get lost overall,
|
||||||
|
but they should be
|
||||||
|
a) not bound to a specific date, even when written in a specific `jrnl` entry, and
|
||||||
|
b) specifically marked as vague ideas in `taskwarrior`.
|
||||||
|
For now, they will be applied the fixed tags `+idea +maybe` in `taskwarrior` and simply
|
||||||
|
transferred date-less.
|
||||||
|
|
||||||
|
An example `jrnl` file:
|
||||||
|
|
||||||
|
```jrnl
|
||||||
|
[2021-10-30 10:16] todotxt
|
||||||
|
This is just a test entry. It shows how tasks in todo blocks are handled.
|
||||||
|
[ ] This is an incomplete task - it will be transferred directly to tw.
|
||||||
|
[x] This is a completed task - it will be logged as completed in tw.
|
||||||
|
[ ] (A) This is an incomplete task which will get assigned high priority in taskwarrior.
|
||||||
|
x This is also a completed task, as long as the x is the first thing on the line with a space behind.
|
||||||
|
x All four of these tasks will be transferred to tw, and their lines deleted from this file.
|
||||||
|
|
||||||
|
idea: This is an idea and it will be transferred to tw with corresponding tags, then deleted from this file.
|
||||||
|
|
||||||
|
This is not a task but a normal line and will remain in the file.
|
||||||
|
xAs will this,
|
||||||
|
[ ]As will this.
|
||||||
|
|
||||||
|
[ ] This will be transferred again, however.
|
||||||
|
|
||||||
|
[2021-10-29 10:16] Another entry
|
||||||
|
This is a regular jrnl entry, since it is missing the correct title.
|
||||||
|
By default it looks for `todotxt` titles,
|
||||||
|
but the title can be freely set for the script (`-b` option).
|
||||||
|
jrnlwarrior will not look for incomplete or completed tasks within this block at all.
|
||||||
|
[x] This is a completed task, but it will not be transferred to taskwarrior.
|
||||||
|
[ ] Neither will this incomplete task.
|
||||||
|
+idea This idea however *will* be transferred, since ideas are looked for in *all* entries.
|
||||||
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
|
@ -52,7 +91,7 @@ If you want to switch off one of the three ways this script connects the two,
|
||||||
you can use the `-L`, `-I`, `-T` options which turn off logging, adding, or creating entries respectively.
|
you can use the `-L`, `-I`, `-T` options which turn off logging, adding, or creating entries respectively.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
./jrnlwarrior.py -I -T
|
./jrnlwarrior.py -DIT
|
||||||
```
|
```
|
||||||
|
|
||||||
The above invocation will *only* log completed tasks to `taskwarrior`.
|
The above invocation will *only* log completed tasks to `taskwarrior`.
|
||||||
|
@ -63,7 +102,7 @@ Adding new to-dos and creating today entries is turned off.
|
||||||
```
|
```
|
||||||
|
|
||||||
This will create a one-way connection to `taskwarrior`,
|
This will create a one-way connection to `taskwarrior`,
|
||||||
by transferring both new and completed tasks to the program.
|
by transferring both new and completed tasks and ideas to the program.
|
||||||
However, tasks to be done today will not be transferred back to this file.
|
However, tasks to be done today will not be transferred back to this file.
|
||||||
|
|
||||||
## Scope
|
## Scope
|
||||||
|
|
|
@ -40,6 +40,9 @@ def process_file(options):
|
||||||
for line in file:
|
for line in file:
|
||||||
line_number += 1
|
line_number += 1
|
||||||
|
|
||||||
|
if handle_idea(line, options):
|
||||||
|
lines_to_delete.append(line_number)
|
||||||
|
|
||||||
todo_block = get_todo_block_date(line, options.todo_block_title)
|
todo_block = get_todo_block_date(line, options.todo_block_title)
|
||||||
if todo_block == False:
|
if todo_block == False:
|
||||||
curdate = ""
|
curdate = ""
|
||||||
|
@ -122,6 +125,33 @@ def add_incomplete_to_taskwarrior(task_string, date, options):
|
||||||
subprocess.Popen(cmd)
|
subprocess.Popen(cmd)
|
||||||
|
|
||||||
|
|
||||||
|
def handle_idea(line, options):
|
||||||
|
completed_task = re.search(
|
||||||
|
rf"^{options.regex_task_idea} (.*)",
|
||||||
|
line,
|
||||||
|
)
|
||||||
|
if completed_task and options.taskwarrior_add_ideas:
|
||||||
|
add_idea_to_taskwarrior(completed_task[1], options)
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def add_idea_to_taskwarrior(idea_string, options):
|
||||||
|
overrides = options.taskwarrior_overrides
|
||||||
|
cmd = [
|
||||||
|
"task",
|
||||||
|
*overrides,
|
||||||
|
"add",
|
||||||
|
"+idea",
|
||||||
|
"+maybe",
|
||||||
|
idea_string,
|
||||||
|
]
|
||||||
|
if options.dryrun:
|
||||||
|
print(cmd)
|
||||||
|
return
|
||||||
|
subprocess.Popen(cmd)
|
||||||
|
|
||||||
|
|
||||||
def get_prio_string(task_string):
|
def get_prio_string(task_string):
|
||||||
prio = re.search(r"^\(([ABC])\) (.*)$", task_string)
|
prio = re.search(r"^\(([ABC])\) (.*)$", task_string)
|
||||||
prio_string = ""
|
prio_string = ""
|
||||||
|
|
10
options.py
10
options.py
|
@ -13,6 +13,7 @@ class Options:
|
||||||
taskwarrior_log_completed: bool = True
|
taskwarrior_log_completed: bool = True
|
||||||
taskwarrior_add_incomplete: bool = True
|
taskwarrior_add_incomplete: bool = True
|
||||||
taskwarrior_fill_today: bool = True
|
taskwarrior_fill_today: bool = True
|
||||||
|
taskwarrior_add_ideas: bool = True
|
||||||
|
|
||||||
# can not yet be changed
|
# can not yet be changed
|
||||||
taskwarrior_overrides: List = field(
|
taskwarrior_overrides: List = field(
|
||||||
|
@ -24,6 +25,7 @@ class Options:
|
||||||
)
|
)
|
||||||
regex_task_completed: str = r"(?:x|\[x\])"
|
regex_task_completed: str = r"(?:x|\[x\])"
|
||||||
regex_task_incomplete: str = r"\[ \]"
|
regex_task_incomplete: str = r"\[ \]"
|
||||||
|
regex_task_idea: str = r"(?:idea:|\+idea)"
|
||||||
|
|
||||||
|
|
||||||
def init():
|
def init():
|
||||||
|
@ -63,6 +65,12 @@ def parse_cmdline_args(options):
|
||||||
help="don't add today's todo items as entry to file",
|
help="don't add today's todo items as entry to file",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-D",
|
||||||
|
"--noidea",
|
||||||
|
help="don't add ideas as maybe items to taskwarrior",
|
||||||
|
action="store_true",
|
||||||
|
)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
if args.dryrun:
|
if args.dryrun:
|
||||||
|
@ -71,6 +79,8 @@ def parse_cmdline_args(options):
|
||||||
options.taskwarrior_log_completed = False
|
options.taskwarrior_log_completed = False
|
||||||
if args.noincomplete:
|
if args.noincomplete:
|
||||||
options.taskwarrior_add_incomplete = False
|
options.taskwarrior_add_incomplete = False
|
||||||
|
if args.noidea:
|
||||||
|
options.taskwarrior_add_ideas = False
|
||||||
if args.nofilltoday:
|
if args.nofilltoday:
|
||||||
options.taskwarrior_fill_today = False
|
options.taskwarrior_fill_today = False
|
||||||
if args.file:
|
if args.file:
|
||||||
|
|
Loading…
Reference in a new issue