Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Wang authored and Andrew Wang committed Jul 9, 2019
0 parents commit 6258f1b
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
__pycache__/*
.vscode/*
env/*
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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'
28 changes: 28 additions & 0 deletions notion-clear-trash.py
Original file line number Diff line number Diff line change
@@ -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.')
17 changes: 17 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 6258f1b

Please sign in to comment.