jasonliuuu / notion-page-sort

Sort through Notion's sub-page by title (or part of its title).

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

📋 Notion Page Sort

Sort through Notion's sub-page by title (or part of its title, such as number 1 in title #1 My Notion Page). Notion Page Sort is a very simple, bare-bone script, with only 40+ lines of code but still utilizes a decent terminal UI.

Config

Modify configurations from line 6 to line 8 in main.py:

# Regex match pattern
pattern = r"#(\d+)\ "

# Notion's Login Cookie
token = "{GET-TOKEN-FROM-LOGINED-NOTION'S-COOKIE}"

# Notion's root page to sort through
url = "{NOTION-PAGE-URL}"

In my case, the regex shown above is matching the pattern where a number comes after #, like #20 in title #20 macOS Menubar. The script takes the 20 as key to sort through the titles.

The token used to log into Notion can be acquired from the developer's console in a already logged-in Notion web page.

Build and run

  1. Install dependencies
pipenv install
  1. Run main.py
# Enter virtual environment
pipenv shell

# Run script
python main.py

FAQ

Q: Why is the sorting process so slow?

Because Notion's web API is slow to access. I am using Notion's unofficial Python API wrapper to implement this script, and I am sorting the subpages with Bubble sort.

Bubble sort is a sorting algorithm which is highly dependent on "swapping" components. In this case, each "swap" is sent out via HTTP requests, and considering how long it takes for us to access Notion, one can understand why exactly is the sorting process so slow.

If (or when) Notion releases their official API, I will try to implement this script using a single web request, so that the sorting can be done offline.

P.S. By the time the API is available, I may or may not consider switching to a faster sorting algorithm, say, Quicksort/TimSort/Merge sort...


📋 Notion Page Sort ©Spencer Woo. Released under the MIT License.

Authored and maintained by Spencer Woo.

@Portfolio · @GitHub · @BIT

About

Sort through Notion's sub-page by title (or part of its title).

License:MIT License


Languages

Language:Python 100.0%