🐍

How to Use Python + Notion

We will use BeautifulSoup to scrap data from ESPN and upload the team name and rosters via the notion API.

To get started we will want to open up a google colab notebook

This is way we will handle the running of the code in one environment.

Next, we will create our notion page.
image

Once we have created our notion page, we will want to input a table to be able to upload the info into a database.

image
Now, title your table and change the ‘Tags’ label to Position. We will be scrapping the headshot, name, and position for now.
image
Go to Notion Developers and create a new Integration
image
Make the title of the integration NBA and store this key as a secret in your colab notebook
image
Next, we will want to enable sharing access to our database. Go back to your notion table and click share. Invite your integration.
image
image

Now we are synced up and can upload data to the table from the API.

Let’s go back over to the google colab notebook now and start inputing some of the functions we will need.

Your notebook should look like this now

image
We are now going to create a python function that will help us find our notion database. This will make it easier to just plug the database into our data.
import pandas as pd
from urllib.parse import urlparse
url = input()
parseurl = urlparse(url)
parseurl[2 : 3]
database = str(parseurl[2 : 3])
print(database.translate({ord(i): None for i in '/,()'}))

This code will create an input function that will allow you to input your notion URL that you generate from shared link from Notion. Click on the copy link, the share button can be found on the tab part of the page.

image

Your code should now look something like this.

image

We now have our database ID.

Next we need to make the secret from our Notion integrations and it’ll be stored in your notebook

Make your secret a variable
secret = "YOUR-NOTION-SECRET"