Skip to content

Instantly share code, notes, and snippets.

@base698
Last active March 25, 2023 17:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save base698/3696f24cbfa478cf35ff25bbb9adeb5e to your computer and use it in GitHub Desktop.
Save base698/3696f24cbfa478cf35ff25bbb9adeb5e to your computer and use it in GitHub Desktop.
Insert your tunnel log into notion database for your own skills page!

Usage

In Notion

  • Create a table page and get the id. Id is part of the URL when you click share.
  • Add the columns in this script: Signed Off (date), Name (title), Status (status)
  • Create an integration and copy the secret key
  • Click the three dots in the upper right corner of the database page and click share with integration. Type in name of your integration

On tunnelflight.com

Python

  • paste the above code into a file called notion.py
  • in the terminal type: export NOTION_API_KEY=<key you copied from your integration>
  • run the commands: cat all-skills.json | python3 notion.py
from pprint import pprint
import os
import sys
import json
from datetime import datetime
from notion_client import Client
# Replace with your API key
NOTION_API_KEY = os.environ.get("NOTION_API_KEY")
notion = Client(auth=NOTION_API_KEY)
# Get the database object
#https://www.notion.so/some_id_here_as_hex?v=&pvs=4
database_id = 'some_id_here'
# Function to insert values into the Notion database
def insert_values(date,name, status, cat, location, instructor):
status = status.lower()
status = status[0].capitalize() + status[1:]
new_page = {
"Signed Off": {"date": {"start": date}},
"Name": {"title": [{"text": {"content": name}}]},
"Status": {"status": {"name": status}},
"Category": {"select": {"name": cat}},
"Location": {"rich_text": [{"text": {"content": location}}]},
"Instructor": {"rich_text": [{"text": {"content": instructor}}]}
}
notion.pages.create(parent={"database_id": database_id}, properties=new_page)
items = json.loads(sys.stdin.read())
for i in items:
date,name, cat, status, location, instructor = i['entry_date'],i['log_skill_name'],i['cat_name'],i['status'],i['log_location_name'],i['log_instructor_name']
date = datetime.fromtimestamp(date)
insert_values(date.isoformat(),name,status,cat,location,instructor)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment