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"
|
||||
|
||||
|
||||
def parse_file(options):
|
||||
def process_file(options):
|
||||
fname = options.jrnl_fname
|
||||
lines_to_delete = []
|
||||
with open(fname) as file:
|
||||
|
@ -45,15 +45,24 @@ def parse_file(options):
|
|||
if not curdate:
|
||||
continue
|
||||
|
||||
completed_task = re.search(r"^(?:x|[x]) ((?:\([A-D]\))? ?.*)$", line)
|
||||
if completed_task and options.taskwarrior_log_completed:
|
||||
log_completed_to_taskwarrior(completed_task[1], curdate, options.dryrun)
|
||||
if handle_completed_tasks(line, curdate, options):
|
||||
lines_to_delete.append(line_number)
|
||||
|
||||
if lines_to_delete:
|
||||
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):
|
||||
prio = re.search(r"^\(([ABC])\) (.*)$", task_string)
|
||||
prio_string = ""
|
||||
|
@ -106,5 +115,5 @@ def delete_logged_tasks_from_file(fname, lines, dryrun):
|
|||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parse_file(options.init())
|
||||
process_file(options.init())
|
||||
sys.exit(0)
|
||||
|
|
|
@ -9,6 +9,8 @@ class Options:
|
|||
todo_block_title: str = "todotxt"
|
||||
dryrun: bool = False
|
||||
taskwarrior_log_completed: bool = True
|
||||
regex_task_completed: str = r"(?:x|[x])"
|
||||
regex_task_incomplete: str = r"[ ]"
|
||||
|
||||
|
||||
def init():
|
||||
|
|
Loading…
Reference in a new issue