Created
August 20, 2019 07:28
-
-
Save iddan/1e86a0c5310a04736a7e9e515e3e8a29 to your computer and use it in GitHub Desktop.
Notion to Pandas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"name": "Notion_to_Pandas.ipynb", | |
"version": "0.3.2", | |
"provenance": [], | |
"collapsed_sections": [] | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
} | |
}, | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "UIUDmd5p34OZ", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"%pip install notion" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "Md13fa5R36xM", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"from getpass import getpass\n", | |
"\n", | |
"print('Go to Notion.so, open developer tools, go to Application tab, Cookies, and copy the value of token_v2')\n", | |
"token = getpass()" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "hSw9gd-Q4Z6V", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"from notion.client import NotionClient\n", | |
"\n", | |
"notion = NotionClient(token_v2=token)\n", | |
"\n", | |
"# This is a link of a table\n", | |
"rows = notion.get_block(block_url).collection.get_rows()\n", | |
"\n", | |
"table_data = [row.get_all_properties() for row in rows]" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "fL9ySGoV46Ah", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"import pandas as pd\n", | |
"\n", | |
"pd.DataFrame(table_data)" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
} | |
] | |
} |
I get an HTTP Error (400) when I try to do something similar
@VianneyMI can you please elaborate?
@iddan whenever I use the get_block method I get an HTTP Error as shown below
Nice work!
Any plans on when this feature gets implemented ?
if mode not in ("a", "append"):
raise NotImplementedError
# TODO: clean the current values in the notion database (if any)
Notion has released an official API now, you can use it, even though it also comes with its own set of challenges
https://developers.notion.com/
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
THANK YOU