Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

add_node inside parser need to be enhanced #30

Open
stone16 opened this issue Jun 28, 2024 · 0 comments
Open

add_node inside parser need to be enhanced #30

stone16 opened this issue Jun 28, 2024 · 0 comments

Comments

@stone16
Copy link

stone16 commented Jun 28, 2024

Faced index out of bound issue before, need to handle the empty/null title list case. Below is the updated working version

    def _add_node(self, block: any, **kwargs):
        """
        :param block: any type of block, page, database
        :kwargs url: page or database url
        """
        url = block.get('url', '')
        title = block.get('title', None)

        if not title or not isinstance(title, str):
            if block.get('object') == 'database':
                title_list = block.get('title', [])
                if title_list and isinstance(title_list, list) and 'plain_text' in title_list[0]:
                    title = title_list[0]['plain_text']
                else:
                    title = 'Untitled'
            elif block.get('object') == 'page':
                properties = block.get('properties', {})
                if block.get('parent', {}).get('type') != "database_id":
                    title_list = properties.get('title', {}).get('title', [])
                    if title_list and isinstance(title_list, list) and 'plain_text' in title_list[0]:
                        title = title_list[0]['plain_text']
                    else:
                        title = 'Untitled'
                else:
                    title_list = properties.get('Name', {}).get('title', [])
                    if title_list and isinstance(title_list, list) and 'plain_text' in title_list[0]:
                        title = title_list[0]['plain_text']
                    else:
                        title = 'Untitled'
            else:
                title = block.get(block.get('type'), {}).get('title', 'Untitled')

        print("+node:", title)
        self._graph.add_node(
            block.get('id', 'unknown_id'),
            label=title,
            title=f'<a href="{url}">open page</a>',
            color=COLOR_NODE,
            size=10,
            borderWidth=0
        )
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant