Kobo to Notion

| Marco Caloba

Context

In today's fast-paced world, personal development is a key focus for many individuals seeking growth and self-improvement. I currently do my best to read approximately 2 books per month, predominantly in the genre of personal development. To ensure that I extract the maximum value from each book, I began compiling book summaries in Notion. These summaries include all my highlights from the readings, accompanied by a more comprehensive 'book overview template' I adapted from youtuber Ali Abdaal.

For over a year, I relied on a website to access my Kobo highlights, manually copying and pasting them into Notion. The idea of automating this process had been lingering in my mind, but it wasn't until the website announced its upcoming closure that I finally took action.

Determined to streamline my note-taking procedure and integrate it seamlessly with Notion, I set out on a quest to automate the process. My search for solutions led me through many possibilities, but it wasn't until I stumbled upon an intriguing blog post that I found a promising starting point. Although her script was implemented in Node.js, which I have limited knowledge of, it inspired me to create my own solution.

Within Julia's blog post, she referenced a repository on GitHub named "Export Kobo," housing a Python script capable of extracting data from the KoboReader.sqlite file and exporting it in various formats. Initially, I considered using this script as it was already an upgrade from my current “system”. However, my goal was to establish a direct connection with Notion, so I got compelled to develop my own script. Initially, I attempted to modify the existing Python script, but the complex organization and structure proved time-consuming to comprehend. Eventually, I decided to start from scratch.

Automation has revolutionised various aspects of our lives, and in my pursuit of personal development, I sought to apply it to my reading process. By developing a Python script, I was able to seamlessly integrate my Kobo highlights with Notion, saving time and effort while preserving the essence of my reading experience.

In the following sections, I will provide a comprehensive breakdown of the script's structure. I researched the subject by diving into various articles and YouTube videos. At the end, I will provide a curated list of the primary resources that greatly influenced the development of this script. It's worth noting that the process involved a significant amount of trial and error, and while I aimed to capture all valuable resources, it's possible that some may have been forgotten.


Script explanation

First and foremost, we need to import the necessary packages:

Since I might change the script’s location later on, I start by getting the folder and file directories. The name “KoboReader.sqlite” will always be the same because I will simply copy and paste it from the Kobo folder, directly to the folder with this script.

Using the ‘notion_client’ package, we only need two variables to work with Notion’s API: the token from a Notion integration, and the id from the Notion page we want to work with. These are really easy to get, just follow these instructions. Note: I replaced some of the letters/numbers with underscores just for this blog’s sake, it is not supposed to be like this:

Since we want to read a file that contains a database, we need to create a connection to read the information stored in it. For this, I created a function that takes the file as an input and then opens the connection with the sqlite3 package.

To actually write the text in a Notion page, you need to append children blocks (you can find more information about this in Notion’s documentation). The function bellow takes 4 inputs: the client (activated through the Notion token, by the notion_cliente package, in the main function), the page id, the text I want to write, and the type of block I want to create (you can find the list of different blocks here). With this information, we can append a children to our page with the format presented below. I found this video to be very helpful in understanding this part.

On to the main function:

  1. The first step is to activate the connection to the SQLite file with the function presented above.

  2. Next, I created two dataframes:

    a. Through an inner join between the ‘content’ and ‘Bookmark’ tables, the ‘books_in_file’ dataframe stores the name, author and last read date of the books that have highlights.

    b. From the ‘Bookmark’ table, the ‘bookmark_df’ dataframe stores all highlights, annotations and the date they were created on, ordering from oldest to newest.

  3. Since there are some highlights that have some unwanted white spaces in the beginning and/or end, I use a for cycle to strip all highlights and keep only clean highlights.

  4. Then, I set the ‘client’ variable with the Notion connection to use it in the final cycle.

  5. To end this main function, I have 2 for cycles with 2 if statements to get all highlights. Here are the steps:

    a. We start by running through all of the books we saved (the ones that have highlights) and write in the notion page a ‘heading 2’ (mid-size title) in the format ‘Book Title - Author’;

    b. Next, we set a second cycle that, for each book saved in the previous cycle, runs through all of it’s highlights;

    c. Then, for each highlight, we set the first condition that checks if the book title we just wrote (in the first step) is in the current highlight’s id.

    d. Lastly, if the previous condition is true, we set a second condition to check if we have a annotation. If it is just a highlight, it writes in Notion a normal ‘paragraph’ with the content. If there is a annotation, first it writes the annotation in ‘quote’ type and then writes the highlight as a ‘paragraph’.

    e. At the end of each book, I also write a blanck paragraph, just to create a visual separation between books.

  6. Just one last step: to run the main function, I wrote a starting block at the end.


Full Python script

Here you can see the full script, but you can also get the it from my GitHub page.


Final product

I might consider some changes in the future but, as of today, these are the steps I need to take to get my highlights in my Notion database:

  1. I connect my Kobo to my laptop and copy the ‘KoboReader.sqlite’ file to the folder where I have the Python script stored.

  2. I run the script in VSCode.

  3. I open my books Notion database and copy the notes from the page I used in the script (the first block in the image below, ‘Kobo to Notion’), to the actual page of the book summary.


Resources

  • Resource 1: This was the first blog that caught my attention when I was searching for ways to connect my Kobo device with Notion.

  • Resource 2: This repository was mentioned the above article, and it is a Python script capable of reading the KoboReader.sqlite file and exporting the data in several formats.

  • Resource 3: This is great playlist (with just 5 minute videos) to understand the basics of reading and writing data through Notion’s API, both in pages and databases.

  • Resource 4: This article was very helpful to understand how I could create a connection to the database with a Python script.

  • Resource 5: I used this website to upload my ‘KoboReader.sqlite’ file, so I could understand how the tables were organised and where was the information I needed.

  • Resource 6: For more informations about Notion’s API, you can also check the official documention available.


LinkdIn; GitHub; Medium; Goodreads.

To read next

Traffic Monitoring REST API

By Marco Caloba

I completed a project centered on building a Django Rest Framework-powered REST API for a road traffic monitoring dashboard. The API manages road segments, capturing crucial data such as average vehicle speed, traffic intensity characterization, and timestamps of recordings. The project includes features like interactive API documentation, data loading into the database, user management via Django Admin, and unit testing.

Daily Quotes

By Marco Caloba

In the past few years, my daily reading habit has evolved into a practice of creating comprehensive book summaries, capturing key insights, quotes, and my personal reflections. These notes represent my commitment to personal growth and being the best version of myself. However, with time, it has become challenging to recall all the valuable teachings I've encountered. To address this, I've centralised my notes and quotes in my Notion's second brain. Taking it a step further, I connected a Python script to Notion's API and seamlessly integrate these personal notes into daily quote emails. This automation not only provides convenient access to motivational quotes but also serves as a periodic reminder of my own insights and reflections.

Kobo to Notion

By Marco Caloba

In today's fast-paced world, personal development is a key focus for many individuals seeking growth and self-improvement. To ensure that I extract the maximum value from each book I read, I began compiling book summaries in Notion. I used to rely on a website to access my Kobo highlights, and manually copy and past them into Notion. Determined to automate this process, I made this Python script that allows me to seamlessly send my Kobo highlights directly to my Notion, saving time and effort while preserving the essence of my reading experience.