From db37e38df7c968f95a5947287a31935617e9a341 Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Sun, 11 Sep 2022 10:47:44 +0300 Subject: [PATCH] Create OrgNode hasBody method. Use it in org_to_jsonl checks --- src/processor/org_mode/org_to_jsonl.py | 6 +++--- src/processor/org_mode/orgnode.py | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/processor/org_mode/org_to_jsonl.py b/src/processor/org_mode/org_to_jsonl.py index 25ab1d9b..93955659 100644 --- a/src/processor/org_mode/org_to_jsonl.py +++ b/src/processor/org_mode/org_to_jsonl.py @@ -106,8 +106,8 @@ def convert_org_nodes_to_entries(entries: list[orgnode.Orgnode], entry_to_file_m for entry in entries: entry_dict = dict() - # Ignore title notes i.e notes with just headings and empty body - if not entry.Body() or re.sub(r'\n|\t|\r| ', '', entry.Body()) == "": + if not entry.hasBody(): + # Ignore title notes i.e notes with just headings and empty body continue entry_dict["compiled"] = f'{entry.Heading()}.' @@ -130,7 +130,7 @@ def convert_org_nodes_to_entries(entries: list[orgnode.Orgnode], entry_to_file_m if state.verbose > 2: logger.debug(f'Scheduled: {entry.Scheduled().strftime("%Y-%m-%d")}') - if entry.Body(): + if entry.hasBody(): entry_dict["compiled"] += f'\n {entry.Body()}' if state.verbose > 2: logger.debug(f"Body: {entry.Body()}") diff --git a/src/processor/org_mode/orgnode.py b/src/processor/org_mode/orgnode.py index 5f47a448..5ad28d88 100644 --- a/src/processor/org_mode/orgnode.py +++ b/src/processor/org_mode/orgnode.py @@ -262,6 +262,12 @@ class Orgnode(object): """ return self.body + def hasBody(self): + """ + Returns True if node has non empty body, else False + """ + return self.body and re.sub(r'\n|\t|\r| ', '', self.body) != '' + def Level(self): """ Returns an integer corresponding to the level of the node.