Giter Site home page Giter Site logo

paperboi / kindle2notion Goto Github PK

View Code? Open in Web Editor NEW
865.0 10.0 114.0 9.09 MB

Export all clippings from your Kindle device to a database in Notion.

Home Page: https://pypi.org/project/kindle2notion/

License: MIT License

Python 100.00%
notion kindle kindle-highlights kindle-clippings notion-py notion-api productivity education reading-notes reading

kindle2notion's Introduction

A program to copy all your Kindle highlights and notes to a page in Notion.
Explore the docs · File issues and feature requests here

If you found this script helpful or appreciate my work, you can support me here:

Kindle2Notion - Export your Kindle clippings to a Notion database. | Product Hunt Buy Me A Coffee

Downloads Contributors Forks Stargazers Issues MIT License LinkedIn

Table of Contents

About The Project

Kindle2Notion Demo

A Python package to export all the clippings from your Kindle device to a page in Notion. Run this script whenever you plug in your Kindle device to your PC.

A key inspiration behind this project was the notes saving feature on Google Play Books, which automatically syncs all your highlights from a book hosted on the service to a Google Doc in real time. I wanted a similar feature for my Kindle and this project is one step towards a solution for this problem.

Intended for

  • Avid readers who would want to browse through their prior reads and highlights anytime anywhere.
  • For those who like to take notes alongside their highlights.

Getting Started

NOTE Need a step-by-step guide to setting this package up? Click here for the full guide.

To get a local copy up and running follow these simple steps:

Prerequisites

  • A Kindle device.
  • A Notion account to store your links.
  • Python 3 on your system to run the code.

Installation & Setup

NOTE As of 10-07-2022, the latest update to this package relies on the offical Notion API for sending API requests. This requires you to create an integration token from here. For old users, you'd have to switch to this method as well since notion-py isn't being maintained anymore.

  1. Install the library.
    pip install kindle2notion
  2. Create an integration on Notion.
    1. Duplicate this database template to your the workspace you want to use for storing your Kindle clippings.
    2. Open Settings & Members from the left navigation bar.
    3. Select the Integrations option listed under Workspaces in the settings modal.
    4. Click on Develop your own integrations to redirect to the integrations page.
    5. On the integrations page, select the New integration option and enter the name of the integration and the workspace you want to use it with. Hit submit and your internal integration token will be generated.
  3. Go back to your database page and click on the Share button on the top right corner. Use the selector to find your integration by its name and then click Invite. Your integration now has the requested permissions on the new database.

Usage

  1. Plug in your Kindle device to your PC.

  2. You need the following three arguments in hand before running the code:

    1. Take your_notion_auth_token from the secret key bearer token provided.
    2. Find your_notion_database_id from the URL of the database you have copied to your workspace. For reference,
      https://www.notion.so/myworkspace/a8aec43384f447ed84390e8e42c2e089?v=...
                                        |--------- Database ID --------|
      
    3. your_kindle_clippings_file is the path to your My Clippings File.txt on your Kindle.
  3. Additionally, you may modify some default parameters of the command-line with the following options of the CLI:

    • --enable_highlight_date Set to False if you don't want to see the "Date Added" information in Notion.
    • --enable_book_cover Set to False if you don't want to store the book cover in Notion.
  4. Export your Kindle highlights and notes to Notion!

    • On MacOS and UNIX,
    kindle2notion 'your_notion_auth_token' 'your_notion_table_id' 'your_kindle_clippings_file'
    • On Windows
    python -m kindle2notion 'your_notion_auth_token' 'your_notion_table_id' 'your_kindle_clippings_file'

You may also avail help with the following command:

kindle2notion --help
python -m kindle2notion --help

NOTE This code has been tested on a 4th Gen Kindle Paperwhite on both MacOS and Windows.

Roadmap

See the open issues for a list of proposed features (and known issues).

Contributing

Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Jeffrey Jacob (Twitter | Email | LinkedIn)

kindle2notion's People

Contributors

adam-tokarski avatar anshulahuja98 avatar djemeljanovs avatar guptaanmol184 avatar horhik avatar imesut avatar jlmbaka avatar johndzxu avatar paperboi avatar rahulakrishna avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kindle2notion's Issues

ENHANCEMENT: Create and maintain JSON object of books and clippings to reduce API calls and update only those clippings that are modified each time.

Create and maintain a JSON object of books and clippings to reduce API calls and update only those clippings that are modified each time.
Motivation:

  • In the current code, there is no way of appending to an existing book with new clippings alone. All the clippings of the book are aggregated together and hence this would lead to duplicate clippings getting written to a book.

Ideal solution:

  • Store all data while parsing into a JSON object of books and clippings and fetch from it when writing to the Notion database.

Issues with running the script

I am getting an error -

Traceback (most recent call last): File "/Users/Pranav/Tools/Kindle2Notion/kindle2notion.py", line 9, in <module> from settings import CLIPPINGS_FILE, NOTION_TOKEN, NOTION_TABLE_ID File "/Users/Pranav/Tools/Kindle2Notion/settings.py", line 5, in <module> CLIPPINGS_FILE = config('CLIPPINGS_FILE') File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/decouple.py", line 199, in __call__ return self.config(*args, **kwargs) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/decouple.py", line 83, in __call__ return self.get(*args, **kwargs) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/decouple.py", line 68, in get raise UndefinedValueError('{} not found. Declare it as envvar or define a default value.'.format(option)) decouple.UndefinedValueError: CLIPPINGS_FILE not found. Declare it as envvar or define a default value.

It seems that I am not storing the path to the clipping file correctly. But I can't tell what's going wrong -

Content of kindle2notion.env file:
CLIPPINGS_FILE = "/Users/Pranav/Tools/Kindle2Notion/MyClippings.txt" NOTION_TOKEN = "fe606a84504eeac4***" NOTION_TABLE_ID = "1fa082d598e34df***"

Possible future developments - as a web app or a executable file

A major takeaway that came out of the Product Hunt and r/Notion launch was that many users found it tedious to go through the process of setting up a Python and pip environment on their system to the program running.
And since this is a program that in turn has a significant target audience outside of STEM, I feel it's important that we develop a distributable version of the program that is more accessible in nature.

  • My first pitch for this is to forward efforts into maintaining the project as a web app that can be hosted online using a framework. The base code for this web app and the package would remain the same and updates for both can be done alongside without too many complexities. I am hoping to stick to using free or open-source frameworks where ever possible- spending not much more than just the hosting fees for the domain (I think this too can be avoided if we use a platform like deta.sh or Vercel for deployment).

  • Alternately for offline use purposes, one can make an executable file for Windows, macOS and Linux using Python's pyinstaller package to further overcome the cognitive load to set up a Python environment for the average non-technical user.

I haven't fully looked into developing these yet as my personal schedule doesn't allow me the time to devote to this project full-time. I'm open to collaborating with any keen developers and UI designers willing to take this often and help put this together.
Feel free to comment below to take this forward.
#40

PS. as of yesterday, the repo touched over 100 commits!

AttributeError: 'str' object has no attribute 'removeprefix'

Hey man, love the idea, this is what I was looking for for a long time.
Encountering this issue when trying to run the module:
Traceback (most recent call last):
File "D:\Python38\lib\runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "D:\Python38\lib\runpy.py", line 87, in run_code
exec(code, run_globals)
File "D:\Python38\lib\site-packages\kindle2notion_main
.py", line 31, in
main()
File "D:\Python38\lib\site-packages\click\core.py", line 1134, in call
return self.main(*args, **kwargs)
File "D:\Python38\lib\site-packages\click\core.py", line 1059, in main
rv = self.invoke(ctx)
File "D:\Python38\lib\site-packages\click\core.py", line 1401, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "D:\Python38\lib\site-packages\click\core.py", line 767, in invoke
return _callback(*args, **kwargs)
File "D:\Python38\lib\site-packages\kindle2notion_main
.py", line 25, in main
books = parse_raw_clippings_text(all_clippings)
File "D:\Python38\lib\site-packages\kindle2notion\parsing.py", line 18, in parse_raw_clippings_text
author, title = _parse_author_and_title(raw_clipping_list)
File "D:\Python38\lib\site-packages\kindle2notion\parsing.py", line 35, in _parse_author_and_title
author, title = _parse_raw_author_and_title(raw_clipping_list)
File "D:\Python38\lib\site-packages\kindle2notion\parsing.py", line 69, in _parse_raw_author_and_title
author = author.removeprefix('(').removesuffix(')')
AttributeError: 'str' object has no attribute 'removeprefix'

Any help? Thanks.

Error: Got unexpected extra argument (Clippings.txt') - in Windows 10

Hi! I'm writting from Chile, the program seems awesome!
I have no skills at all in coding but I followed the steps and managed to install python, pip and kindle 2notion package. Could you please help me out? Thanx a lot!!!! I would really appreciate it!

`C:\Program Files\Python39>py -m kindle2notion
.... (i deleted the token, url and kindle path from the message i got)

Usage: python -m kindle2notion [OPTIONS] NOTION_TOKEN NOTION_TABLE_ID
CLIPPINGS_FILE_PATH
Try 'python -m kindle2notion --help' for help.

Error: Got unexpected extra argument (Clippings.txt')`

AttributeError: 'str' object has no attribute 'removeprefix'

I'm tryna running the script, but this error log has occurred.

python3 kindle2notion.py
Notion page is found. Analyzing clippings file...

Found 328 notes and highlights.

'str' object has no attribute 'removeprefix'
Exiting script...
sh: pause: command not found

AttributeError: 'str' object has no attribute 'removeprefix'

Trying to emulate the process laid down in the README.md file.
Got this error. The script successfully identified the clippings file and the notion table but not able to complete the process.

Initial output:

Notion page is found. Analyzing clippings file...
Found 105 notes and highlights.

Showing error in this line:

kindle2notion\parsing.py", line 69, in _parse_raw_author_and_title
 author = author.removeprefix('(').removesuffix(')')
AttributeError: 'str' object has no attribute 'removeprefix'

Export kindle clipping with Chapter name.

Hi, I don't really know where to ask but if someone know the way to export highlight with chapter name it's really helpful for later review (For now we only have location in book)

AttributeError: 'NoneType' object has no attribute 'strftime'

Hi! This is my first issue report, if I have missed something, just let me know.

I am on mac (m1 macbook air) and have installed the latest version of the repo and python. When I updated python with homebrew I received the following:

Warning: You are using macOS 13.
We do not provide support for this pre-release version.
You will encounter build failures with some formulae.
Please create pull requests instead of asking for help on Homebrew's GitHub,
Twitter or any other official channels. You are responsible for resolving
any issues you experience while you are running this
pre-release version.


Warning: Ruby version 2.6.10 is unsupported on macOS 13. Homebrew
is developed and tested on Ruby 2.6.9, and may not work correctly
on other Rubies. Patches are accepted as long as they don't cause breakage
on supported Rubies.

Here is what I get when I try to sync the hightlights:

Notion page is found. Analyzing clippings file...
Found 2 notes and highlights.
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.10/bin/kindle2notion", line 33, in <module>
    sys.exit(load_entry_point('kindle2notion==1.0.1', 'console_scripts', 'kindle2notion')())
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/kindle2notion/__main__.py", line 41, in main
    all_books = parse_raw_clippings_text(all_clippings)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/kindle2notion/parsing.py", line 96, in parse_raw_clippings_text
    page, location, date, isNote = _parse_page_location_date_and_note(
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/kindle2notion/parsing.py", line 144, in _parse_page_location_date_and_note
    date = date.strftime("%A, %d %B %Y %I:%M:%S %p")
AttributeError: 'NoneType' object has no attribute 'strftime'

[enhancement] Sort using page number and location

When we go back to the book which we have already read and then make new highlights, they ##are populating at the end of the Notion pages. So it would be great, if it is possible to sort the highlight snippets using page number and location.

Line 9 error import CLIPPINGS_FILE, NOTION_TOKEN, NOTION_TABLE_ID

I just finished the installation, when I ran the terminal I was giving an error on lines 40 and 49. I couldn't solve it.

So I installed pycharm, I'm using a Linux Mint 20.0 distribution

I would like to test the script, I am looking for a script or app that has interaction with Kindle and Notion.

Thank you.

"from more_itertools import grouper" needs to commented on the packages.

Really small issue and easy to solve as it is correct right now on GitHub.
This line of code on exporting.py needs to be commented

from more_itertools import grouper # Not good

# from more_itertools import grouper #Good

Again this is fixed on the repo but not on the packages.

I found this by downloading the package from pip and kept getting this error:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.10/bin/kindle2notion", line 33, in <module>
    sys.exit(load_entry_point('kindle2notion==1.0.0', 'console_scripts', 'kindle2notion')())
  File "/Library/Frameworks/Python.framework/Versions/3.10/bin/kindle2notion", line 25, in importlib_load_entry_point
    return next(matches).load()
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/importlib/metadata/__init__.py", line 171, in load
    module = import_module(match.group('module'))
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/kindle2notion/__main__.py", line 5, in <module>
    from kindle2notion.exporting import export_to_notion
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/kindle2notion/exporting.py", line 11, in <module>
    from more_itertools import grouper
ModuleNotFoundError: No module named 'more_itertools'

Raising this issue in case someone else's finds it and it's wondering wtf is happening.

Error if pageorloc formatting deviates from expected format

I have experienced the following error:
Traceback (most recent call last):
File "kindle2notion.py", line 200, in
ch = KindleClippings(CLIPPINGS_FILE)
File "kindle2notion.py", line 13, in init
self.clippings = self._getAllClippings(clippingsFile)
File "kindle2notion.py", line 18, in _getAllClippings
return self._parseClippings(allClippings)
File "kindle2notion.py", line 96, in _parseClippings
self.addToNotion(lastClip)
File "kindle2notion.py", line 185, in addToNotion
title = "Page: " + lastClip['Page'] + "\tDate Added: " + str(lastClip['Date Added'].strftime("%A, %d %B %Y %I:%M:%S %p"))
TypeError: must be str, not NoneType

The cause is that my Kindle is storing my strings as:

  • Your Highlight on Location

Which is a bit of a deviation from what kindle2notion expects.

I think its probably easier to make the parsing here a bit more robust, probably by doing the following:

  • convert case down to lower to make it case agnostic
  • attempt to find substring "page" or "location" in order to check if it is a page or a location
  • filter out all characters which are not digits or hyphens in order to get the meaningful information

May suggest this as a push.

TypeError: issubclass() arg 1 must be a class

Describe the bug
I'm running the script in the normal fashion: kindle2notion INTEGRATION_KEY DATABASE_ID FILE_LOC.

To Reproduce
kindle2notion INTEGRATION_KEY DATABASE_ID FILE_LOC.

Expected behaviour
The program uploads my clippings to Notion.

Screenshots

Initiating transfer...

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.10/bin/kindle2notion", line 33, in <module>
    sys.exit(load_entry_point('kindle2notion==1.0.1', 'console_scripts', 'kindle2notion')())
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/kindle2notion/__main__.py", line 44, in main
    export_to_notion(
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/kindle2notion/exporting.py", line 36, in export_to_notion
    message = _add_book_to_notion(
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/kindle2notion/exporting.py", line 97, in _add_book_to_notion
    notion.databases.query(notion_database_id)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/notional/session.py", line 356, in query
    if issubclass(target, ConnectedPage):
TypeError: issubclass() arg 1 must be a class

Desktop (please complete the following information):

  • OS: MacOS

Additional context
Here's a link to my clippings.

Incoporate logs and update status

  • Since updation can take anywhere from less than a minute to 30 because of the Notion API calls, a log stating incremental updates is required
  • Possibilities for a progress bar

IndexError: list index out of range

Hi! I am trying to use the tool for the first time, all issues which I had I was able to solve with the help of previous closed issues but..
I am running kindle2notion on mac os and now I run into an issue, which I haven't found so I opened a new one.
here is a short traceback

Notion page is found. Analyzing clippings file...
Found 652 notes and highlights.

Traceback (most recent call last):
  File "/opt/anaconda3/bin/kindle2notion", line 8, in <module>
    sys.exit(main())
  File "/opt/anaconda3/lib/python3.8/site-packages/click/core.py", line 1134, in __call__
    return self.main(*args, **kwargs)
  File "/opt/anaconda3/lib/python3.8/site-packages/click/core.py", line 1059, in main
    rv = self.invoke(ctx)
  File "/opt/anaconda3/lib/python3.8/site-packages/click/core.py", line 1401, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/opt/anaconda3/lib/python3.8/site-packages/click/core.py", line 767, in invoke
    return __callback(*args, **kwargs)
  File "/opt/anaconda3/lib/python3.8/site-packages/kindle2notion/__main__.py", line 25, in main
    books = parse_raw_clippings_text(all_clippings)
  File "/opt/anaconda3/lib/python3.8/site-packages/kindle2notion/parsing.py", line 18, in parse_raw_clippings_text
    author, title = _parse_author_and_title(raw_clipping_list)
  File "/opt/anaconda3/lib/python3.8/site-packages/kindle2notion/parsing.py", line 35, in _parse_author_and_title
    author, title = _parse_raw_author_and_title(raw_clipping_list)
  File "/opt/anaconda3/lib/python3.8/site-packages/kindle2notion/parsing.py", line 68, in _parse_raw_author_and_title
    author = (re.findall(r'\(.*?\)', raw_clipping_list[0]))[-1]
IndexError: list index out of range

Does anybody know how to solve this issue?

Transferred content has quotation-marks and apostrophes removed.

Hi.

I just updated kindle2notion from 0.1.2 to 0.1.7.

I took a backup of all my Clippings in Notion, deleted the original pages and transferred the content from 'My Clippings.txt' to a fresh Notion database.

Now all quotation-marks and apostrophes are missing when displayed in Notion. Now all the lines just kind of blend in with another, I am not able to separate what is thought, description or quotes.

The quotation-marks and apostrophes are still present in 'My Clippings.txt' and even in my backup Clippings Notion Database (used kindle2notion 0.1.2, so I know that this was working before).

HTTPError

Not sure what went wrong here

Code:

Traceback (most recent call last):
File "/Users/denise/Kindle2Notion/kindle2notion.py", line 151, in
cv = client.get_collection_view(NOTION_TABLE_ID)
File "/usr/local/lib/python3.9/site-packages/notion/client.py", line 165, in get_collection_view
collection = self.get_block(
File "/usr/local/lib/python3.9/site-packages/notion/client.py", line 118, in get_block
block = self.get_record_data("block", block_id, force_refresh=force_refresh)
File "/usr/local/lib/python3.9/site-packages/notion/client.py", line 111, in get_record_data
return self._store.get(table, id, force_refresh=force_refresh)
File "/usr/local/lib/python3.9/site-packages/notion/store.py", line 184, in get
self.call_load_page_chunk(id)
File "/usr/local/lib/python3.9/site-packages/notion/store.py", line 286, in call_load_page_chunk
recordmap = self._client.post("loadPageChunk", data).json()["recordMap"]
File "/usr/local/lib/python3.9/site-packages/notion/client.py", line 209, in post
raise HTTPError(
requests.exceptions.HTTPError: Invalid input.

No module named 'regex._regex'

Traceback (most recent call last):
File "/usr/lib/python3.9/runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/usr/lib/python3.9/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/home/main/.local/lib/python3.9/site-packages/kindle2notion/main.py", line 4, in
from kindle2notion.exporting import export_to_notion
File "/home/main/.local/lib/python3.9/site-packages/kindle2notion/exporting.py", line 4, in
from dateparser import parse
File "/home/main/.local/lib/python3.9/site-packages/dateparser/init.py", line 3, in
from .date import DateDataParser
File "/home/main/.local/lib/python3.9/site-packages/dateparser/date.py", line 6, in
import regex as re
File "/usr/lib/python3/dist-packages/regex/init.py", line 1, in
from .regex import *
File "/usr/lib/python3/dist-packages/regex/regex.py", line 402, in
import regex._regex_core as _regex_core
File "/usr/lib/python3/dist-packages/regex/_regex_core.py", line 21, in
import regex._regex as _regex
ModuleNotFoundError: No module named 'regex._regex'

401 Client Error: Unauthorized for url: https://www.notion.so/api/v3/loadUserContent

Hi, I am trying again (yesterday was working) and I face issues with the HTTP Client. I also tried logging in and out from Notion and getting a new token, but the issue is still there.

Traceback (most recent call last):
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.1776.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.1776.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\pfern\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\kindle2notion\__main__.py", line 49, in <module>
    main()
  File "C:\Users\pfern\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\click\core.py", line 1137, in __call__
    return self.main(*args, **kwargs)
  File "C:\Users\pfern\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\click\core.py", line 1062, in main
    rv = self.invoke(ctx)
  File "C:\Users\pfern\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\click\core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "C:\Users\pfern\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\click\core.py", line 763, in invoke
    return __callback(*args, **kwargs)
  File "C:\Users\pfern\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\kindle2notion\__main__.py", line 31, in main
    notion_client = NotionClient(token_v2=notion_token)
  File "C:\Users\pfern\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\notion\client.py", line 95, in __init__
    self._update_user_info()
  File "C:\Users\pfern\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\notion\client.py", line 126, in _update_user_info
    records = self.post("loadUserContent", {}).json()["recordMap"]
  File "C:\Users\pfern\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\notion\client.py", line 265, in post
    response.raise_for_status()
  File "C:\Users\pfern\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\requests\models.py", line 953, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
**requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://www.notion.so/api/v3/loadUserContent**

Unable to run kindle2notion

I am getting the following error when attempting to run kindle2notion python package.

Executed Command: kindle2notion 86j559ih250... https://www.notion.so/h1l947gj1... '.\Desktop\My Clippings.txt'

Error recieved:

Traceback (most recent call last):
  File "C:\Users\trimble\AppData\Local\Programs\Python\Python39\Scripts\kindle2notion-script.py", line 33, in <module>
    sys.exit(load_entry_point('kindle2notion', 'console_scripts', 'kindle2notion')())
  File "c:\users\trimble\appdata\local\programs\python\python39\lib\site-packages\click\core.py", line 1134, in __call__
    return self.main(*args, **kwargs)
  File "c:\users\trimble\appdata\local\programs\python\python39\lib\site-packages\click\core.py", line 1059, in main
    rv = self.invoke(ctx)
  File "c:\users\trimble\appdata\local\programs\python\python39\lib\site-packages\click\core.py", line 1401, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "c:\users\trimble\appdata\local\programs\python\python39\lib\site-packages\click\core.py", line 767, in invoke
    return __callback(*args, **kwargs)
  File "c:\users\trimble\desktop\shortcuts\playground\fun\kindle2notion\kindle2notion\__main__.py", line 20, in main
    notion_collection_view = notion_client.get_collection_view(notion_table_id)
  File "c:\users\trimble\appdata\local\programs\python\python39\lib\site-packages\notion\client.py", line 165, in get_collection_view
    collection = self.get_block(
  File "c:\users\trimble\appdata\local\programs\python\python39\lib\site-packages\notion\client.py", line 118, in get_block
    block = self.get_record_data("block", block_id, force_refresh=force_refresh)
  File "c:\users\trimble\appdata\local\programs\python\python39\lib\site-packages\notion\client.py", line 111, in get_record_data
    return self._store.get(table, id, force_refresh=force_refresh)
  File "c:\users\trimble\appdata\local\programs\python\python39\lib\site-packages\notion\store.py", line 184, in get
    self.call_load_page_chunk(id)
  File "c:\users\trimble\appdata\local\programs\python\python39\lib\site-packages\notion\store.py", line 286, in call_load_page_chunk
    recordmap = self._client.post("loadPageChunk", data).json()["recordMap"]
  File "c:\users\trimble\appdata\local\programs\python\python39\lib\site-packages\notion\client.py", line 209, in post
    raise HTTPError(
requests.exceptions.HTTPError: Invalid input.

Error on line 151 on the notion database ID

I ran the script and I have the erreor : "If 'url_or_id' is an ID (not a URL), you must also pass the 'collection'"

I used the ID from my notion database for clippings (before the "?").

Do you know what's the issue ? I'm running it on windows

Thanks

Excellent tool 👏

Hey Jeffrey,

I found your script today and currently migrating all of my kindle notes to notion. Thank you so much for that code. It saves me lots of time :)

I want to get you a coffee for writing this code. Would you feel like creating a Buy me a coffee page so that others could also donate for you?

Invalid collection view URL

~ kindle2notion '53daebe5e31867d66528004e6f9b209f8e95889af9e39aad3ba6a774336e39edc78b39a8323c817c36f9cdaefa64085a494f0a89c2af2c26ca96ccab9e9ca301c3b11a************' 'https://www.notion.so/*******/ecd48369d2f64b53bfae2ad349afc264\?v\=a2fd7fae297f4a6999010e8d168c767c' '/Volumes/Kindle/documents/My\ Clippings.txt'
Traceback (most recent call last):
File "/usr/local/bin/kindle2notion", line 8, in
sys.exit(main())
File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1134, in call
return self.main(*args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1059, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1401, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python3.9/site-packages/click/core.py", line 767, in invoke
return __callback(*args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/kindle2notion/main.py", line 32, in main
notion_collection_view = notion_client.get_collection_view(notion_table_id)
File "/usr/local/lib/python3.9/site-packages/notion/client.py", line 163, in get_collection_view
raise Exception("Invalid collection view URL")
Exception: Invalid collection view URL

[HELP] Unable to connect with Notion

When I try to run the script, it gives me the following error:

Traceback (most recent call last):
File "kindle2notion.py", line 9, in
from settings import CLIPPINGS_FILE, NOTION_TOKEN, NOTION_TABLE_ID, ENABLE_HIGHLIGHT_DATE
File "F:\k2n\settings.py", line 5, in
CLIPPINGS_FILE = config('CLIPPINGS_FILE')
File "C:\Users\Technolet\AppData\Local\Programs\Python\Python37\lib\site-packages\decouple.py", line 199, in call
return self.config(*args, **kwargs)
File "C:\Users\Technolet\AppData\Local\Programs\Python\Python37\lib\site-packages\decouple.py", line 83, in call
return self.get(*args, **kwargs)
File "C:\Users\Technolet\AppData\Local\Programs\Python\Python37\lib\site-packages\decouple.py", line 68, in get
raise UndefinedValueError('{} not found. Declare it as envvar or define a default value.'.format(option))
decouple.UndefinedValueError: CLIPPINGS_FILE not found. Declare it as envvar or define a default value.

I believe it is due to something I am not doing correctly when creating the .env file. I am a beginner so I don't know what I am doing wrong.

Content of k2n.env file:
CLIPPINGS_FILE = "‪F:\k2n\My Clippings.txt"
NOTION_TOKEN = "7fed1060c5efc2d9a08329935c2e99c85ae834df0c86cbab1aec3aeb69c00f890e2ec4e17971c4824ddad240842151d2e753c5ca58faa68859d3776ba1d71b1e88aa9d8d702e9ff984940*******"
NOTION_TABLE_ID = "https://www.notion.so/zainkhan/1d7805cf81014931b77aa36c83cd6618?v=354a8fe2452a4b13b766a7843*******"
ENABLE_HIGHLIGHT_DATE = True

Looking forward to the help and thank you in advance.

APIResponseError: API token is invalid

Hi, this is most probably not a bug, but and issue between chair and keyboard:)
I'm not a developer, so intalling Kindle2Notion wasn't an easy task, but I managed it. But when I tried to export the clippings from kindle to Notion by running the Kindle2Notion package, i'm getting error
notion_client.errors.APIResponseError: API token is invalid
It seems like a least expected problem, because I simply go to Notion's 'Setting & Members' > Integrations and copy Internal Integration token. Don't understand what could be an issue here. I tried to reinstall the package, but didn't help. Any advice will be highly appreciated! Thanks!

Non-English language support

With a Kindle in Portuguese, highlights's location and date aren't added in Notion... I think the problem is date format, that is different in portuguese.
I tested change language to English, and create a new highlight; this one was exported correct (it's the last registre in the file).
My Clippings.txt

Dockerize the thing

That could be dockerized. Docker allows to speed up development and ease deployment, especially when CI/CD is involved.

Code fails when Author information isn't present in the clippings file

Noticed that some Kindle titles don't have Author information. I faced this issue with "The Intelligent Investor" that I bought from the Kindle Store.

While it doesn't seem possible to fetch the Author info, it can be made so the code gracefully fails and uses an empty string for Author Name. I used a fix locally to get around the issue. Will make a PR later today if this issue is accepted.

Attaching images of clippings file and error message below.

image

image

Add linter/formatter

There is nice tool which takes care of Python code format just by forcing to one specified style (PEP8): black.

Can't install kindle2notion. setuptools not available in the build environment.

C:\Users\Nashit Ahmed Barq>python -m pip install kindle2notion
Collecting kindle2notion
Using cached kindle2notion-0.1.8.tar.gz (11 kB)
Preparing metadata (setup.py) ... done
Collecting click>=8.0.0
Using cached click-8.0.4-py3-none-any.whl (97 kB)
Collecting dateparser>=1.0.0
Using cached dateparser-1.1.0-py2.py3-none-any.whl (288 kB)
Collecting DateTime>=4.3
Using cached DateTime-4.4-py2.py3-none-any.whl (51 kB)
Collecting notion>=0.0.27
Using cached notion-0.0.28-py3-none-any.whl (43 kB)
Collecting python-decouple>=3.3
Using cached python_decouple-3.6-py3-none-any.whl (9.9 kB)
Collecting requests>=2.25.0
Using cached requests-2.27.1-py2.py3-none-any.whl (63 kB)
Collecting pathlib
Using cached pathlib-1.0.1.tar.gz (49 kB)
Preparing metadata (setup.py) ... error
error: subprocess-exited-with-error

× python setup.py egg_info did not run successfully.
│ exit code: 1
╰─> [1 lines of output]
ERROR: Can not execute setup.py since setuptools is not available in the build environment.
[end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

Deletes Highlights

Hi.

I have experienced this issue multiple times today. When adding the latest highlights from my clippings file it somehow deleted existing clipping from "Warbreaker" Page and inserted "Oathbringer" highlights into the "Warbreaker" page.

It seems to have been solved by deleting all pages in "My Clipping" database and running the script on My Clippings file.
Do the script require "My Clippings" to not contain any existing Highlights?

Error Handling Preventing Script Termination

  File "/Applications/kindle2notion/kindle2notion.py", line 200, in <module>
    ch = KindleClippings(CLIPPINGS_FILE)
  File "/Applications/kindle2notion/kindle2notion.py", line 13, in __init__
    self.clippings = self._getAllClippings(clippingsFile)
  File "/Applications/kindle2notion/kindle2notion.py", line 18, in _getAllClippings
    return self._parseClippings(allClippings)
  File "/Applications/kindle2notion/kindle2notion.py", line 96, in _parseClippings
    self.addToNotion(lastClip)
  File "/Applications/kindle2notion/kindle2notion.py", line 185, in addToNotion
    title = "Page: " + lastClip['Page'] + "\tDate Added: " +  str(lastClip['Date Added'].strftime("%A, %d %B %Y %I:%M:%S %p"))
TypeError: can only concatenate str (not "NoneType") to str

Need error handling for such errors to prevent termination of script

Not writing to Notion

I've followed instructions and don't get an error upon executing the command, but the clippings are not actually written to the Notion database. In fact, the database remains unchanged from the template.

image

Pop OS 20.10
Kindle Paperwhite (3rd Gen)

Exception trying to extract title and author

Given a complex book title consisting of more than one word in brackets, for example:
Смерть Ивана Ильича (Russian Edition) (Толстой, Лев Николаевич)

The following exception is thrown:
Traceback (most recent call last): File "kindle2notion.py", line 242, in <module> ch = KindleClippings(CLIPPINGS_FILE) File "kindle2notion.py", line 13, in __init__ self.clippings = self._getAllClippings(clippingsFile) File "kindle2notion.py", line 18, in _getAllClippings return self._parseClippings(allClippings) File "kindle2notion.py", line 27, in _parseClippings title, author = title_author.split('|') ValueError: too many values to unpack (expected 2)

HTTPError( requests.exceptions.HTTPError: Invalid input.) - Even after changing the limit to 100

Traceback (most recent call last):
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2032.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2032.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 87, in run_code
exec(code, run_globals)
File "C:\Users\hello\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\kindle2notion_main
.py", line 49, in
main()
File "C:\Users\hello\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\click\core.py", line 1137, in call
return self.main(*args, **kwargs)
File "C:\Users\hello\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\click\core.py", line 1062, in main
rv = self.invoke(ctx)
File "C:\Users\hello\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\click\core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "C:\Users\hello\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\click\core.py", line 763, in invoke
return _callback(*args, **kwargs)
File "C:\Users\hello\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\kindle2notion_main
.py", line 38, in main
export_to_notion(
File "C:\Users\hello\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\kindle2notion\exporting.py", line 35, in export_to_notion
message = _add_book_to_notion(
File "C:\Users\hello\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\kindle2notion\exporting.py", line 87, in _add_book_to_notion
notion_collection_view_rows = notion_collection_view.collection.get_rows()
File "C:\Users\hello\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\notion\collection.py", line 239, in get_rows
return self.query(**kwargs)
File "C:\Users\hello\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\notion\collection.py", line 236, in query
return CollectionQuery(self, self._get_a_collection_view(), **kwargs).execute()
File "C:\Users\hello\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\notion\collection.py", line 385, in execute
self._client.query_collection(
File "C:\Users\hello\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\notion\client.py", line 294, in query_collection
return self._store.call_query_collection(*args, **kwargs)
File "C:\Users\hello\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\notion\store.py", line 344, in call_query_collection
response = self._client.post("queryCollection", data).json()
File "C:\Users\hello\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\notion\client.py", line 260, in post
raise HTTPError(
requests.exceptions.HTTPError: Invalid input.

I used this without any error but recently installed SSD in my machine with a fresh install of windows. And installed python just to use this amazing script, but getting this error. I followed the solution and changed the limit to 100, but it isn't working anymore.

Page data missing, Wrong/different language/editions book covers listed & Incomplete/wrongly formatted highlights

The code works really well! Thanks for sharing it. Although there are some small bugs:

  1. My highlights do not show the page they were highlighted
  2. Many books bought from Amazon have no cover, and some have the wrong ones.
    3)Unfortunately, some highlights are incomplete and have some errors.
    I am not proposing any solution because I have no idea about code, but I hope you can fix it!
    One last question, is there any way of just updating it without running the whole code again?
    Thanks

Date conversion is not handled properly

Date extraction in line 52 assumes the formatting of the date string.
dateAdded = datetime.strptime(addedOn, ' Added on %A, %d %B %Y %X')
Thursday, 18 April 2019 21:12:17

My kindle is actually formatted as:
e.g. Thursday, April 18, 2019 9:12:17 PM

The fix is actually not that hard to implement, change line 52 to:
dateAdded = datetime.strptime(addedOn, ' Added on %A, %B %d, %Y %X %p')

However, may be worthwhile to sanity check the formatting of dates in the clipping object, or to use a more robust dateparser. After stripping out the "Added on " out of the string.
An example:
https://dateparser.readthedocs.io/en/latest/

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.