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

Just recently it came to my attention that Readwise now offers an App called Reader. Readwise has been around for several years and is a tool to manage your personal highlights discovered in text somewhere in the digital sphere. Recently, they added Reader as a fully fledged Feed reader and Read-it-later client beautifully combined in a single app, which really reduces the friction I experienced with Readwise before.

The fancy part is that Reader integrates the highlighting mechanism of Readwise. Plus, it offers automations for several note taking applications, such as Obsidian an Notion. Supernotes, however, is not officially supported.

End of Story?

Not at all, for where there is an API, there is a way! We can use pipedream to connect both tools using their APIs.

I created a workflow on pipedream (which is really lowcode) that creates a new note whenever I add a highlight to Readwise. This is as easy as selecting text in the Reader app, or in the Browser using the Readwise extension.

Pipedream now creates a note, which respects the syntax I traditionally use for literature notes. I can even add a personal note to the selection in Readwise, which is then also exported.

Pretty sweet, right? This even works for Youtube videos, as Readwise Reader allows for highlighting text in the transcript!

In Pipedream, I had to insert a Python step to get details on the book from the Readwise API, particularly the website title and author that I use to compose the note.

Code Example and Instructions

To compose my card after a new highlight in Readwise triggers, first I gather some additional data in to consecutive python steps which I need in the card’s markup. To begin with, I make a call to the Readwise API in order to retrieve some information on the book (which contains the book or website, and the author) using this 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(
        f'https://readwise.io/api/v2/books/{highlight["book_id"]}',
        headers={"Authorization": f'Token {readwise_auth}'}
    )
    # Export data for use in future steps
    return result.json()

Further, I prepare some pre-formatted strings

import tld
import re
import dateutil.parser as p

def get_domain_base(url):
    dom = ""
    try:
        res = tld.get_tld(url, as_object=True)
        dom = f'{res.domain}.{res.tld}'
    except:
        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
    }