README written – option for all titles in the script

This commit is contained in:
André Hilbig 2021-12-10 11:52:26 +01:00
parent 2b5ef5d855
commit 362e10b1fe
Signed by: ahilbig
GPG Key ID: 7CD69479C2659156
2 changed files with 29 additions and 8 deletions

View File

@ -10,6 +10,15 @@ exported with the marked text in that plain text file.
send the pdf via email to your kindle. I really don't know why or how you can do it without amazon. 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. If someone knows how to do that, please tell me.
python readClip -b Booktitle [-i path/to/Clippings.txt] python readClip [-b Booktitle] [-i path/to/Clippings.txt]
You can use the bash to save the output to a file: python readClip > output.md
### Booktitle
You can search for one booktitle with -b or just print all books. It is not neccessary to include
the whole title, it is enough to find a matching with the title. If you have a lot of similar
titles, you may want to specify the search. Otherwise just the first finding will get printed.
### Clippings
Per default the script searches for `My\ Clippings.txt` in the working directory.

View File

@ -9,7 +9,7 @@ parser.add_argument('-i', type=argparse.FileType("r"),\
help='Input Clippings') help='Input Clippings')
parser.add_argument('-b', type=str,\ parser.add_argument('-b', type=str,\
dest='book', \ dest='book', \
help='Book to search for') help='Booktitle to search for')
args=parser.parse_args() args=parser.parse_args()
@ -39,26 +39,38 @@ def printLines(s):
newEntry = 0 newEntry = 0
foundBook = False foundBook = False
foundBookPast = False foundBookPast = False
bookOld = ""
for line in iline: for line in iline:
if line.find("==========") == -1: if line.find("==========") == -1:
if newEntry == 1: if newEntry == 1:
foundBook = False foundBook = False
book = line book = line
if book.find(args.book) != -1: if args.book:
foundBook = True if book.find(args.book) != -1:
if not foundBookPast: foundBook = True
if not foundBookPast:
print("# " + line)
print("## Anmerkungen")
foundBookPast = True
else:
if bookOld != line:
foundBook = True
print("# " + line) print("# " + line)
print("## Anmerkungen") print("## Anmerkungen")
foundBookPast = True bookOld = line
newEntry = newEntry + 1 newEntry = newEntry + 1
elif foundBook: elif foundBook:
if newEntry == 2: if newEntry == 2:
page = line.split('Seite ')[1].split('|', 1)[0].strip() if line.find("Seite") != -1:
splt = 'Seite '
else:
splt = 'Position '
page = line.split(splt)[1].split('|', 1)[0].strip()
if page.find('-') != -1: if page.find('-') != -1:
if page.split('-')[0] == page.split('-')[1]: if page.split('-')[0] == page.split('-')[1]:
page = page.split('-')[0] page = page.split('-')[0]
if line.find("Markierung") != -1: if line.find("Markierung") != -1:
print("- Seite " + page + ":") print("- " + splt + page + ":")
if line.find("Notiz") != -1: if line.find("Notiz") != -1:
print("- Seite " + page + " (*Notiz*):") print("- Seite " + page + " (*Notiz*):")
elif newEntry > 2: elif newEntry > 2: