First version of readClip
This commit is contained in:
parent
2767386999
commit
2b5ef5d855
14
README.md
14
README.md
@ -1,3 +1,15 @@
|
||||
# readclip
|
||||
|
||||
readclip reads the My\ Clippings.txt from your kindle device and exports it to Markdown.
|
||||
readclip reads the My\ Clippings.txt from your kindle device and exports it to Markdown.
|
||||
|
||||
## Useage
|
||||
Copy the `My\ Clippings.txt` from your Kindle device. Usually all your highlighting and notes are
|
||||
exported with the marked text in that plain text file.
|
||||
|
||||
*Hint:* If you copy a pdf directly on your device, the Clippings-file gets empty. You'll need to
|
||||
send the pdf via email to your kindle. I really don't know why or how you can do it without amazon.
|
||||
If someone knows how to do that, please tell me.
|
||||
|
||||
python readClip -b Booktitle [-i path/to/Clippings.txt]
|
||||
|
||||
|
||||
|
69
readClip.py
Normal file
69
readClip.py
Normal file
@ -0,0 +1,69 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
import argparse
|
||||
#import locale
|
||||
|
||||
parser = argparse.ArgumentParser(description='Get Options.')
|
||||
parser.add_argument('-i', type=argparse.FileType("r"),\
|
||||
dest='clp', default='./My Clippings.txt',\
|
||||
help='Input Clippings')
|
||||
parser.add_argument('-b', type=str,\
|
||||
dest='book', \
|
||||
help='Book to search for')
|
||||
|
||||
args=parser.parse_args()
|
||||
|
||||
iline = args.clp.readlines()
|
||||
|
||||
def printLines(s):
|
||||
pre = " "
|
||||
width = 80
|
||||
words=s.split()
|
||||
line = ''
|
||||
for word in words:
|
||||
if len(word) > width and len(line) == 0:
|
||||
print(pre + word)
|
||||
else:
|
||||
if len(word) + len(line) < width:
|
||||
if len(line) == 0:
|
||||
line = pre + word
|
||||
else:
|
||||
line = line + " " + word
|
||||
else:
|
||||
print(line)
|
||||
line = pre + word
|
||||
if len(line) > 0:
|
||||
print(line)
|
||||
|
||||
|
||||
newEntry = 0
|
||||
foundBook = False
|
||||
foundBookPast = False
|
||||
for line in iline:
|
||||
if line.find("==========") == -1:
|
||||
if newEntry == 1:
|
||||
foundBook = False
|
||||
book = line
|
||||
if book.find(args.book) != -1:
|
||||
foundBook = True
|
||||
if not foundBookPast:
|
||||
print("# " + line)
|
||||
print("## Anmerkungen")
|
||||
foundBookPast = True
|
||||
newEntry = newEntry + 1
|
||||
elif foundBook:
|
||||
if newEntry == 2:
|
||||
page = line.split('Seite ')[1].split('|', 1)[0].strip()
|
||||
if page.find('-') != -1:
|
||||
if page.split('-')[0] == page.split('-')[1]:
|
||||
page = page.split('-')[0]
|
||||
if line.find("Markierung") != -1:
|
||||
print("- Seite " + page + ":")
|
||||
if line.find("Notiz") != -1:
|
||||
print("- Seite " + page + " (*Notiz*):")
|
||||
elif newEntry > 2:
|
||||
if line.strip() != "":
|
||||
printLines(line)
|
||||
newEntry = newEntry + 1
|
||||
else:
|
||||
newEntry = 1
|
Loading…
Reference in New Issue
Block a user