Comments (5)
You can use a snippet from Readme for each page:
for page_id in space.pages:
page = client.get_block(page_id)
print(page.title)
for child in page.children:
print(child.title)
from notion-py.
After digging a bit deeper, I found that this is not enough.
What you need is to call client.post("loadUserContent", {}).json()["recordMap"]["block"].keys()
to fetch ids of all pages and then iterate through all the children blocks of types 'page' and 'collection'. Maybe there are more block types that displayed as pages (like collection_view), but I didn't need them for my task.
This is a dirty and inefficient but working example of how to do this — https://github.com/eoranged/notion-scripts/blob/master/audit.py
from notion-py.
I've added a client.get_top_level_pages
method in #87 based on @eoranged's code suggestion. This will be released soon in a new version.
For the recursion, you can just use standard recursion to loop down through the descendants to do whatever you like with them. For example:
def recursively_print_titles(block, depth=0):
print("\t" * depth + block.title)
for child in block.children:
if child.type in ["page", "collection"]:
recursively_print_titles(child, depth=depth+1)
for block in client.get_top_level_pages():
recursively_print_titles(block)
(but it's going to be slowwwww, if you have a ton of pages)
EDIT: added conditional so it wouldn't include other types of blocks (e.g. page contents)
from notion-py.
I believe this get_top_level_pages method is broken. It's pretty tough to replicate but I am getting plenty of pages which are not top-level pages in some cases (as attested by the fact that the parent_table is not 'space'). I think it needs a check on the parent_table to work (would also be interested to know why it loads so many more unneccessary blocks already).
from notion-py.
Is there a way for an third party app integration to access list of all page ids?
from notion-py.
Related Issues (20)
- HTTPERROR using children.add_new
- collection.add_row() fails on new databases HOT 2
- How to set database column calculation?
- Not documented: how to set the size of an image HOT 1
- > this is a pretty paralyzing issue. does anyone know how long it will take for it to get merged in? HOT 1
- Uploading image doesn't work HOT 2
- Need to cut a new release
- Notion crashes when setting CollectionView filter with no id HOT 2
- Is this module still work now? I got an error, outdated? HOT 1
- Failed To Run "setup.py" Due To Encoding Error
- requests.exceptions.HTTPError: Invalid input from client.get_block HOT 8
- Unsaved transactions: SpaceShardRecordPointer have no space id HOT 1
- raise InvalidNotionIdentifier(input_value)
- Help!!! requests.exceptions.HTTPError: Invalid input. HOT 4
- TypeError: Retry.__init__() got an unexpected keyword argument 'method_whitelist' HOT 3
- Client POST generates a HTTPError HOT 1
- (question) is there `get_all_comments`? HOT 1
- notion_client.errors.RequestTimeoutError: Request to Notion API has timed out
- HTTPError (400) when trying to load a database despite trying proposed solutions HOT 3
- Search (and find best matching page titles)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from notion-py.