minwook-shin / notion-database

Python bindings for Notion Database API
https://pypi.org/project/notion-database/
GNU Lesser General Public License v3.0
137 stars 12 forks source link

Adding advanced children blocks #3

Closed imohitmayank closed 2 years ago

imohitmayank commented 2 years ago

First of all, thanks for the package - it's crisp and to the point πŸ‘

So while playing around with the code, I tried to create a new page with some "complex" content (Children) that could be a combination of text, embed elements, etc. Currently, it seems the Children class only supports normal text, I was thinking is it possible to add support for other blocks as well?

Btw I managed to create a workaround for my task using the following class,

class NewChildren:
    result = []

    def add_text(self, text):
        self.result.append({'object': 'block',
         'type': 'paragraph',
         'paragraph': {'text': [{'type': 'text',
         'text': {'content': text}}]}})

    def add_embed(self, link):
        self.result.append({'object': 'block',
         'type': 'embed',
         'embed': {'url': link}})

Maybe something on similar lines? Thanks again!

minwook-shin commented 2 years ago

hello. your idea is good! however, due to my working time, I'm slowly developing this notion package. maybe, one of these days...?

by the way, PR is welcome. thank you.

if start developing that feature, i'll mention again.

minwook-shin commented 2 years ago

Hello. @imohitmayank . start developing! :) its being developed in develop branch. and most of children blocks will implemented.

package will deploy tomorrow. coming soon!

thank you.

minwook-shin commented 2 years ago

implemented it now. children Blocks are supported! πŸŽ‰

Install notion-database==20210816.3, and check the changed code in README.

example :

children = Children()
# children.set_body("hello world!")  # deprecated. set_body -> set_paragraph
children.set_paragraph("set_paragraph")

children.set_heading_1("set_heading_1")
children.set_heading_2("set_heading_2")
children.set_heading_3("set_heading_3")

children.set_callout("set_callout")

children.set_quote("set_quote")

children.set_bulleted_list_item("set_bulleted_list_item")

children.set_numbered_list_item("set_numbered_list_item")

children.set_to_do("set_to_do", checked=True)

children.set_toggle("set_toggle", children_text="WOW!")

children.set_code("print(\"hello world!\")", lang='python')

children.set_embed("https://www.google.com")

children.set_external_image("https://github.githubassets.com/images/modules/logos_page/Octocat.png")
children.set_external_video("http://download.blender.org/peach/trailer/trailer_480p.mov")
children.set_external_file("https://github.com/microsoft/ML-For-Beginners/raw/main/pdf/readme.pdf")
children.set_external_pdf("https://github.com/microsoft/ML-For-Beginners/blob/main/pdf/readme.pdf")

children.set_bookmark("https://www.google.com")

children.set_equation("e=mc^2")

children.set_divider()
children.set_table_of_contents()
children.set_breadcrumb()

thanks again, @imohitmayank !

imohitmayank commented 2 years ago

This is great! Will check it out. Thnx for the quick response ☺️