Refactor file processing function
This commit is contained in:
parent
7fdf83f3fe
commit
e548fa6edb
2 changed files with 16 additions and 5 deletions
|
@ -27,7 +27,7 @@ def get_todo_block_date(line, todo_block_title):
|
||||||
return "same"
|
return "same"
|
||||||
|
|
||||||
|
|
||||||
def parse_file(options):
|
def process_file(options):
|
||||||
fname = options.jrnl_fname
|
fname = options.jrnl_fname
|
||||||
lines_to_delete = []
|
lines_to_delete = []
|
||||||
with open(fname) as file:
|
with open(fname) as file:
|
||||||
|
@ -45,15 +45,24 @@ def parse_file(options):
|
||||||
if not curdate:
|
if not curdate:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
completed_task = re.search(r"^(?:x|[x]) ((?:\([A-D]\))? ?.*)$", line)
|
if handle_completed_tasks(line, curdate, options):
|
||||||
if completed_task and options.taskwarrior_log_completed:
|
|
||||||
log_completed_to_taskwarrior(completed_task[1], curdate, options.dryrun)
|
|
||||||
lines_to_delete.append(line_number)
|
lines_to_delete.append(line_number)
|
||||||
|
|
||||||
if lines_to_delete:
|
if lines_to_delete:
|
||||||
delete_logged_tasks_from_file(fname, lines_to_delete, options.dryrun)
|
delete_logged_tasks_from_file(fname, lines_to_delete, options.dryrun)
|
||||||
|
|
||||||
|
|
||||||
|
def handle_completed_tasks(line, date, options):
|
||||||
|
completed_task = re.search(
|
||||||
|
rf"^{options.regex_task_completed} ((?:\([A-D]\))? ?.*)$",
|
||||||
|
line,
|
||||||
|
)
|
||||||
|
if completed_task and options.taskwarrior_log_completed:
|
||||||
|
log_completed_to_taskwarrior(completed_task[1], date, options.dryrun)
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
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 = ""
|
||||||
|
@ -106,5 +115,5 @@ def delete_logged_tasks_from_file(fname, lines, dryrun):
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
parse_file(options.init())
|
process_file(options.init())
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
|
@ -9,6 +9,8 @@ class Options:
|
||||||
todo_block_title: str = "todotxt"
|
todo_block_title: str = "todotxt"
|
||||||
dryrun: bool = False
|
dryrun: bool = False
|
||||||
taskwarrior_log_completed: bool = True
|
taskwarrior_log_completed: bool = True
|
||||||
|
regex_task_completed: str = r"(?:x|[x])"
|
||||||
|
regex_task_incomplete: str = r"[ ]"
|
||||||
|
|
||||||
|
|
||||||
def init():
|
def init():
|
||||||
|
|
Loading…
Reference in a new issue