This was originally posted by @freisatz in the Supernotes Community.

Discover a seamless way to integrate Readwise with Supernotes, even though it’s not official integration (yet!). Leverage the power of APIs and Pipedream to create a workflow that automates note-taking.

The Flow

  1. Readwise Highlight: Select text in the Reader app or using the Readwise extension.
  2. Pipedream Trigger: A new highlight in Readwise triggers the Pipedream workflow.
  3. Get Book Details: A Python step retrieves book details (title and author) from the Readwise API.
  4. Create Supernotes Card: The workflow composes a new card in Supernotes, respecting your traditional syntax for literature notes.

Code Example and Instructions

Get started by using two consecutive Python steps to retrieve book information and format the note.

After a new highlight is triggered in Readwise, compose your card by gathering additional data in two consecutive Python steps for the card’s markup, first making a call to the Readwise API to retrieve some information on the book, which contains the book or website and the author, using the following code:

import requests

def handler(pd: "pipedream"):
    # Prepare inputs
    readwise_auth = pd.inputs["readwise"]["$auth"]["access_token"]
    highlight = pd.steps["trigger"]["event"]
    # Request data from Readwise API
    result = requests.get(
        headers={"Authorization": f'Token {readwise_auth}'}
    # Export data for use in future steps
    return result.json()

Then prepare some pre-formatted strings

import tld
import re
import dateutil.parser as p

def get_domain_base(url):
    dom = ""
        res = tld.get_tld(url, as_object=True)
        dom = f'{res.domain}.{res.tld}'
        dom = url
    return dom

def get_indented_text(text):
    prefix = "> "
    return re.sub("\n", f"\n{prefix}", re.sub("^", prefix, text))

def get_date(timestamp, date_format):
    d = p.parse(timestamp)
    return d.strftime(date_format)

def handler(pd: "pipedream"):
    # Set constants
    date_format = "%d.%m.%Y"

    # Prepare inputs
    book = pd.steps["book"]["$return_value"]
    highlight = pd.steps["trigger"]["event"]

    # Get domain base
    url = book["source_url"]
    domain_base = get_domain_base(url)

    # Get indented text
    text = highlight["text"]
    indented_text = get_indented_text(text)

    # Get highlight date
    book_updated = book["updated"]
    formatted_date = get_date(book_updated, date_format)

    # Return data for use in future steps
    return {
        "formatted_date": formatted_date,
        "domain_base": domain_base,
        "indented_text": indented_text

Get started with Pipedream and connect Readwise to Supernotes today!