lxyu / kindle-clippings Goto Github PK
View Code? Open in Web Editor NEWA simple python script to extract clippings from 'My Clippings.txt', organize, store and output them in a more elegant way.
Home Page: http://lxyu.github.com/kindle-clippings/
A simple python script to extract clippings from 'My Clippings.txt', organize, store and output them in a more elegant way.
Home Page: http://lxyu.github.com/kindle-clippings/
Highlights have data like "Location 1513-1514" but notes can look like "Location 1514" so these are not picked up by the script. Maybe a regex like 'Location (\d+)' instead of '(\d+)-\d+'
I had a lot of books that had a ":" character in the title
Can be fixed by changing line 51 to:
filename = os.path.join(OUTPUT_DIR, u"%s.txt" % book.replace(":", ""))
The script works great, but there's no license for it. Any plan to provide it?
I know msgpack is great, but I don't see any significant benefits in this project. πΆ
Isn't that great if this project comes with no external dependency? π
I have the same problem described here
http://stackoverflow.com/questions/22620965/ioerror-errno-22-invalid-mode-wb-or-filename
I was wondering whether the filename could be normalized, at least under windows, before creating the file with the filename of the title.
For the moment I'm importing unicodedata and using the following verbose code (and not immune to errors, as I allow the \ to be in the filename, as it is used for referring to the partial path) in export_txt to make things work:
try:
with open(filename, 'wb') as f:
f.write("\n\n---\n\n".join(lines))
except:
oldfilename = filename
filename = unicodedata.normalize('NFKD', filename).encode('ascii','ignore')
valid_chars = '\\-_.() abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
filename = ''.join(c for c in filename if c in valid_chars)
print 'Converting', oldfilename, 'to', filename
with open(filename, 'wb') as f:
f.write("\n\n---\n\n".join(lines))
Thanks
For each book, a dict X is created using a string of the clip position as key.
Then clips are written for each pos in sorted(X), so that e.g. "3748" comes before "410".
For the moment I'm using an inefficient:
for pos in sorted([int(x) for x in clips[book].keys()]):
in export_txt.
Traceback (most recent call last):
File "kindle.py", line 94, in <module>
main()
File "kindle.py", line 89, in main
save_clips(clips)
File "kindle.py", line 70, in save_clips
json.dump(clips, f)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/json/__init__.py", line 180, in dump
fp.write(chunk)
TypeError: a bytes-like object is required, not 'str'
Documents can have titles split with a newline, currently the script assumes the title is a single line so it does not find the Location in the expected line. Maybe get_sections can remove the newlines in the title.
It might be worth showing an error when a Location can't be found - this situation should not exist ?
Looks like this repo has fallen out of maintenance. Could you please hand over maintenance to someone else? If no one else is enthusiastic about doing it, I could.
The script doesn't process the whole file. Output folder has only few notes.
My Clippings.txt
To allow the script to be installed on a path it might be nice to create the output dir if it does not exist (rather than assuming the script is run from within the repository only). Thanks for making this available!
ι误代η ε¦δΈοΌ
Traceback (most recent call last):
File "kindle.py", line 94, in
main()
File "kindle.py", line 90, in main
export_txt(clips)
File "kindle.py", line 50, in export_txt
with open(filename, 'w') as f:
IOError: [Errno 2] No such file or directory: u'output/Who Moved My Cheese? (Spencer Johnson).md'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.