lastorel / pytion

Unofficial Python client for official Notion API
GNU General Public License v3.0
44 stars 3 forks source link

Image support (external media URL or Covers) #52

Closed Pio-github closed 1 year ago

Pio-github commented 1 year ago

Hi ! I'd like to add an image, either in the page.cover or in the page.media.external.url properties so i can visualize my DB in gallery mode. I've seen i could add an image to a block inside the page with Pytion, but i'd rather use cover or properties. (edit: actually i think neither can i)

I'm not sure it's undoable with pytion, but i couldn't find anything =/

If not, it would be a nice feature to add :)

Thanks !

lastorel commented 1 year ago

There is no support for editing the page cover or the page "files" property at the moment.

Only "url" type is supported. And it works for gallery view, I can see the picture from external URL.

Create page example:

from pytion import Notion 
from pytion.models import PropertyValue, LinkTo

no = Notion(token="x")
pv = PropertyValue.create(type_="url", value="https://example.com/image.jpg")  # for editing one of properties of the page
parent = LinkTo.create(database_id="bc339ec71988466c95c083359e239a7c")  # enter database ID to create the page inside
page = no.pages.page_create(parent=parent, title="Some title", properties={"Picture": pv})  # "Picture" is the property name

Almost the same for updating:

page.page_update(properties={"Picture": pv})
Pio-github commented 1 year ago

Why didn't i try URL =/

Thanks a lot for all the work and your quick answer !