Create OrgNode hasBody method. Use it in org_to_jsonl checks

This commit is contained in:
Debanjum Singh Solanky 2022-09-11 10:47:44 +03:00
parent b4878d76ea
commit db37e38df7
2 changed files with 9 additions and 3 deletions

View file

@ -106,8 +106,8 @@ def convert_org_nodes_to_entries(entries: list[orgnode.Orgnode], entry_to_file_m
for entry in entries: for entry in entries:
entry_dict = dict() entry_dict = dict()
if not entry.hasBody():
# Ignore title notes i.e notes with just headings and empty body # 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()) == "":
continue continue
entry_dict["compiled"] = f'{entry.Heading()}.' 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: if state.verbose > 2:
logger.debug(f'Scheduled: {entry.Scheduled().strftime("%Y-%m-%d")}') logger.debug(f'Scheduled: {entry.Scheduled().strftime("%Y-%m-%d")}')
if entry.Body(): if entry.hasBody():
entry_dict["compiled"] += f'\n {entry.Body()}' entry_dict["compiled"] += f'\n {entry.Body()}'
if state.verbose > 2: if state.verbose > 2:
logger.debug(f"Body: {entry.Body()}") logger.debug(f"Body: {entry.Body()}")

View file

@ -262,6 +262,12 @@ class Orgnode(object):
""" """
return self.body 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): def Level(self):
""" """
Returns an integer corresponding to the level of the node. Returns an integer corresponding to the level of the node.