Generate Google Sheets rows for new items in Notion database
Tags: #notion #operations #automation #googlesheets
Description: This notebook allows users to automatically generate Google Sheets rows for new items added to a database using Notion.
from naas_drivers import notion, gsheet
import pandas as pd
- Share integration with your database
# Enter Token API
NOTION_TOKEN = "*****"
# Enter Database URL
DATABASE_URL = "https://www.notion.so/********"
# Unique column name for notion
col_unique_notion = "Name"
- Share your sheet with our service account : 🔗 [email protected]
# Spreadsheet URL
SPREADSHEET_URL = "------"
# Sheet name
SHEET_NAME = "Sheet1"
# Unique column# for gsheets
col_unique_gsheet = "Name"
# Schedule your notebook every hours
naas.scheduler.add(cron="0 * * * *")
# -> Uncomment the line below to remove your scheduler
# naas.scheduler.delete()
db_notion = notion.connect(NOTION_TOKEN).database.get(DATABASE_URL)
df_notion = db_notion.df()
df_gsheet = gsheet.connect(SPREADSHEET_URL).get(sheet_name=SHEET_NAME)
df_gsheet
# Iterate through all rows in Notion database and find match in Google Sheets
# If no match is found then add data to df_difference dataframe
df_difference = pd.DataFrame()
for index, row in df_notion.iterrows():
x = row[col_unique_notion]
if not (x == df_gsheet[col_unique_gsheet]).any():
df_difference = df_difference.append(df_notion.loc[index])
# Send data to Google Sheets
gsheet.connect(SPREADSHEET_URL).send(
sheet_name=SHEET_NAME,
data=df_difference,
append=True,
)
Last modified 1mo ago