diff --git a/README.md b/README.md index 7d59406..caee48c 100644 --- a/README.md +++ b/README.md @@ -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. 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. diff --git a/readClip.py b/readClip.py index 4436b74..d79be75 100644 --- a/readClip.py +++ b/readClip.py @@ -9,7 +9,7 @@ parser.add_argument('-i', type=argparse.FileType("r"),\ help='Input Clippings') parser.add_argument('-b', type=str,\ dest='book', \ - help='Book to search for') + help='Booktitle to search for') args=parser.parse_args() @@ -39,26 +39,38 @@ def printLines(s): newEntry = 0 foundBook = False foundBookPast = False +bookOld = "" 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: + if args.book: + if book.find(args.book) != -1: + foundBook = True + if not foundBookPast: + print("# " + line) + print("## Anmerkungen") + foundBookPast = True + else: + if bookOld != line: + foundBook = True print("# " + line) print("## Anmerkungen") - foundBookPast = True + bookOld = line newEntry = newEntry + 1 elif foundBook: 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.split('-')[0] == page.split('-')[1]: page = page.split('-')[0] if line.find("Markierung") != -1: - print("- Seite " + page + ":") + print("- " + splt + page + ":") if line.find("Notiz") != -1: print("- Seite " + page + " (*Notiz*):") elif newEntry > 2: