Localisation

This commit is contained in:
André Hilbig 2021-12-16 16:43:18 +01:00
parent 362e10b1fe
commit 6d7119334a
Signed by: ahilbig
GPG Key ID: 7CD69479C2659156

View File

@ -1,8 +1,8 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import argparse import argparse
#import locale
# Parse Options
parser = argparse.ArgumentParser(description='Get Options.') parser = argparse.ArgumentParser(description='Get Options.')
parser.add_argument('-i', type=argparse.FileType("r"),\ parser.add_argument('-i', type=argparse.FileType("r"),\
dest='clp', default='./My Clippings.txt',\ dest='clp', default='./My Clippings.txt',\
@ -10,14 +10,33 @@ parser.add_argument('-i', type=argparse.FileType("r"),\
parser.add_argument('-b', type=str,\ parser.add_argument('-b', type=str,\
dest='book', \ dest='book', \
help='Booktitle to search for') help='Booktitle to search for')
parser.add_argument('-w', type=int,\
dest='width', default='80',\
help='Width for long strings')
parser.add_argument('--page', type=str,\
dest='page', default='Seite',\
help='Localisation for term »page«')
parser.add_argument('--pos', type=str,\
dest='pos', default='Position',\
help='Localisation for term »position«')
parser.add_argument('--mark', type=str,\
dest='mark', default='Markierung',\
help='Localisation for term »highlight«')
parser.add_argument('--note', type=str,\
dest='note', default='Notiz',\
help='Localisation for term »note«')
parser.add_argument('--head', type=str,\
dest='head', default='Anmerkung',\
help='Localisation for term »note«')
args=parser.parse_args() args=parser.parse_args()
iline = args.clp.readlines() iline = args.clp.readlines()
# def for printing lines with fixed width
def printLines(s): def printLines(s):
pre = " " pre = " "
width = 80 width = args.width
words=s.split() words=s.split()
line = '' line = ''
for word in words: for word in words:
@ -40,7 +59,11 @@ newEntry = 0
foundBook = False foundBook = False
foundBookPast = False foundBookPast = False
bookOld = "" bookOld = ""
# read every line in the clipfile
for line in iline: for line in iline:
# search for new entry to begin with ==…
# if you find it, search for the right booktitle or just print it rightaway
# if you are in an entry, print the position/page and so on
if line.find("==========") == -1: if line.find("==========") == -1:
if newEntry == 1: if newEntry == 1:
foundBook = False foundBook = False
@ -50,29 +73,30 @@ for line in iline:
foundBook = True foundBook = True
if not foundBookPast: if not foundBookPast:
print("# " + line) print("# " + line)
print("## Anmerkungen") print("## " + args.head)
foundBookPast = True foundBookPast = True
else: else:
if bookOld != line: if bookOld != line:
foundBook = True foundBook = True
print("# " + line) print("# " + line)
print("## Anmerkungen") print("## " + args.head)
bookOld = line bookOld = line
newEntry = newEntry + 1 newEntry = newEntry + 1
elif foundBook: elif foundBook:
if newEntry == 2: if newEntry == 2:
if line.find("Seite") != -1: if line.find(args.page) != -1:
splt = 'Seite ' splt = args.page + ' '
else: else:
splt = 'Position ' splt = args.pos + ' '
page = line.split(splt)[1].split('|', 1)[0].strip() 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(args.mark) != -1:
print("- " + splt + page + ":") print("- " + splt + page + ":")
if line.find("Notiz") != -1: if line.find(args.note) != -1:
print("- Seite " + page + " (*Notiz*):") print("- " + args.page + " " + page + " (*" \
+ args.note + "*):")
elif newEntry > 2: elif newEntry > 2:
if line.strip() != "": if line.strip() != "":
printLines(line) printLines(line)