jamalex / notion-py

Unofficial Python API client for Notion.so
MIT License
4.3k stars 473 forks source link

how to get page block notion #303

Open byndstd opened 3 years ago

byndstd commented 3 years ago

I'm trying to get a notion page block using notion.py but I didn't succeed my code is

from notion.client import NotionClient
import time

# Log in
token_v2 = "The_Token_Number"
client = NotionClient(token_v2 = token_v2)

# Connection to the page

## The page to read
list_url_read = 'https://www.url_of_the_page_1'

page_read = client.get_block(list_url_read)
### collection_read = client.collection.collection_view(list_url_read)

## The page to post
list_url_post = 'https://www.url_of_the_page_2'

### page_post = client.get_block(list_url_post)
collection_post = client.get_collection_view(list_url_post) 

## Insert In page read
new_row = collection_post.collection.add_row()
new_row.title = page_read.title
new_row.status = page_read.status

The page one that I want to get it's block value is : https://i.stack.imgur.com/LFqM0.png

~/dprojects/pyt$ python3 auto_notion_read.py

Traceback (most recent call last):
  File "auto_notion_read.py", line 19, in <module>
    collection_read = client.get_collection_rows(list_url_read)
AttributeError: 'NotionClient' object has no attribute 'get_collection_rows'
byndstd commented 3 years ago

anyone can help please?

kamikazebr commented 3 years ago

Try give us more information, which errors occours? Post some logs and etc. Maybe so more people can help you.

byndstd commented 3 years ago

Try give us more information, which errors occours? Post some logs and etc. Maybe so more people can help you.

this the error

lotfi@Lenovo:~/dprojects/pyt$ python3 auto_notion_read.py 
Traceback (most recent call last):
  File "auto_notion_read.py", line 19, in <module>
    collection_read = client.get_collection_rows(list_url_read)
AttributeError: 'NotionClient' object has no attribute 'get_collection_rows'
kamikazebr commented 3 years ago

@byndstd your line comment out is different from the error

### collection_read = client.collection.collection_view(list_url_read)

Anyway the method get_collection_rows its from client._store its not public acess, you can check that copy and paste the name in search box of git repository.

And check the documentation in the start page looking for that method.

https://github.com/jamalex/notion-py#example-working-with-databases-aka-collections-tables-boards-etc image

Its probaly what you want


cv = client.get_collection_view("https://www.notion.so/myorg/8511b9fc522249f79b90768b832599cc?v=8dee2a54f6b64cb296c83328adba78e1")

# List all the records with "Bob" in them
for row in cv.collection.get_rows(search="Bob"):

Check that and hope it can help you

byndstd commented 3 years ago

@byndstd your line comment out is different from the error

### collection_read = client.collection.collection_view(list_url_read)

Anyway the method get_collection_rows its from client._store its not public acess, you can check that copy and paste the name in search box of git repository.

And check the documentation in the start page looking for that method.

https://github.com/jamalex/notion-py#example-working-with-databases-aka-collections-tables-boards-etc image

Its probaly what you want


cv = client.get_collection_view("https://www.notion.so/myorg/8511b9fc522249f79b90768b832599cc?v=8dee2a54f6b64cb296c83328adba78e1")

# List all the records with "Bob" in them
for row in cv.collection.get_rows(search="Bob"):

Check that and hope it can help you

I didn't work I post the code and error

from notion.client import NotionClient
import time

# Log in
token_v2 = "tocken_2"
client = NotionClient(token_v2 = token_v2)

# Connection to the page

## The page to read
list_url_read = 'url_page_read'

collection_read = client.get_collection_view(list_url_read)

for row in collection_read.collection.get_rows(search="Bob"):
    print("We estimate the value of '{}' at {}".format(row.name, row.estimated_value))

## The page to post
list_url_post = 'url_page_to_post'

collection_post = client.get_collection_view(list_url_post)

The error is

lotfi@Lenovo:~/dprojects/pyt$ python3 auto_notion_read.py 
Traceback (most recent call last):
  File "auto_notion_read.py", line 16, in <module>
    collection_read = client.get_collection_view(list_url_read)
  File "/home/lotfi/.local/lib/python3.6/site-packages/notion/client.py", line 214, in get_collection_view
    raise Exception("Invalid collection view URL")
Exception: Invalid collection view URL
lotfi@Lenovo:~/dprojects/pyt$