From 6258f1b24d199bf09922dd558d053b643cd3ccf1 Mon Sep 17 00:00:00 2001 From: Andrew Wang Date: Tue, 9 Jul 2019 14:09:32 -0400 Subject: [PATCH] Initial commit --- .gitignore | 3 +++ README.md | 27 +++++++++++++++++++++++++++ notion-clear-trash.py | 28 ++++++++++++++++++++++++++++ requirements.txt | 17 +++++++++++++++++ 4 files changed, 75 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 notion-clear-trash.py create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d4da468 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +__pycache__/* +.vscode/* +env/* \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..81fdbfa --- /dev/null +++ b/README.md @@ -0,0 +1,27 @@ +# notion-clear-trash + +A small script to clear the trash from Notion + +### How to Run the Script + +1. Clone the repository +```bash +git clone https://github.com/w4v3s/notion-clear-trash.git +``` +2. Install requirements +```bash +pip3 install -r requirements.txt +``` +3. Run python script +```bash +python3 notion-clear-trash.py +``` + +### How to Retrieve the Auth Token (in Chrome) + +1. Go to notion.so +2. Open developer tools (hit F12) +3. Navigate to the Application tab (may be hidden if the developer window is small) +4. Expand Cookies under the Storage section on the sidebar +5. Click on 'https://www.notion.so' to view all the cookies +6. Copy the value for the key 'token_v2' diff --git a/notion-clear-trash.py b/notion-clear-trash.py new file mode 100644 index 0000000..24f36b6 --- /dev/null +++ b/notion-clear-trash.py @@ -0,0 +1,28 @@ +from notion.client import NotionClient + + +def get_trash(client): + query = { + 'query': '', + 'limit': 1000, + 'spaceId': client.current_space.id + } + results = client.post('searchTrashPages', query) + block_ids = results.json()['results'] + + return block_ids + + +def delete_permanently(client, block_ids): + for block_id in block_ids: + client.post("deleteBlocks", {"blockIds": [block_id], "permanentlyDelete": True}) + + +if __name__== "__main__": + token = input('Please enter your auth token: ') + client = NotionClient(token_v2=token) + + block_ids = get_trash(client) + delete_permanently(client, block_ids) + + print('Successfully cleared all trash blocks.') \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..1554d0a --- /dev/null +++ b/requirements.txt @@ -0,0 +1,17 @@ +beautifulsoup4==4.7.1 +bs4==0.0.1 +cached-property==1.5.1 +certifi==2019.6.16 +chardet==3.0.4 +commonmark==0.9.0 +dictdiffer==0.8.0 +future==0.17.1 +idna==2.8 +notion==0.0.23 +python-slugify==3.0.2 +pytz==2019.1 +requests==2.22.0 +soupsieve==1.9.2 +text-unidecode==1.2 +tzlocal==1.5.1 +urllib3==1.25.3