kindle manager

This commit is contained in:
gavin
2020-06-04 09:27:14 +08:00
parent 1c39315285
commit b57297a443
5 changed files with 26 additions and 13 deletions

23
kman.py
View File

@@ -59,7 +59,8 @@ SYS = 'WIN' if platform.system()=='Windows' else \
# some constants
LASTLINE = '=========='
NTPREF = '--CG注:'
CLIPPATH = './My Clippings.txt' # /Volumes/Kindle/documents/My\ Clippings.txt
#CLIPPATH = './My Clippings.txt' # /Volumes/Kindle/documents/My\ Clippings.txt
CLIPPATH = './tclip.txt'
OUTPREF = './clip'
DEBUG = 1 # 0 - INFO; 1 - DEBUG
LOG2FILE = 1 # 0 - to stdio; 1 - to file
@@ -368,13 +369,13 @@ def json2dict(jf):
d=json.load(f)
return d
if __name__=='__main__':
def import_clips():
# 4 lines for each section seperated with '======='
# so read 4 lines before '======='
# loop to fill books dict
with open(CLIPPATH, 'r', encoding='utf8', errors='ignore') as f:
books = defaultdict(dict)
bks = defaultdict(dict)
secd = defaultdict(dict)
sidx = 0
idx = 0
@@ -403,14 +404,14 @@ if __name__=='__main__':
bn = secd['bookname']
tpy = secd[bn][str(sidx)]['type']
books[bn]['author'] = secd[bn]['author']
books[bn][str(sidx)] = secd[bn][str(sidx)]
bks[bn]['author'] = secd[bn]['author']
bks[bn][str(sidx)] = secd[bn][str(sidx)]
# not add note to highlight content here,
# because NT maybe duplicated, we need remove duplication record before
"""
if tpy=='NT' and books[bn][str(sidx-1)]['type']=='HL':
books[bn][str(sidx-1)]['content'] += str(NTPREF+sec[2])
if tpy=='NT' and bks[bn][str(sidx-1)]['type']=='HL':
bks[bn][str(sidx-1)]['content'] += str(NTPREF+sec[2])
"""
else: # BM or not correct format section
@@ -418,6 +419,12 @@ if __name__=='__main__':
# initial section for next section loop
sec = []
return bks
if __name__=='__main__':
#books = defaultdict(dict)
books = import_clips()
# remove duplication
drop_duplicate(books)
@@ -443,5 +450,3 @@ if __name__=='__main__':
# print data with json format
logger.debug(json.dumps(books, indent=4, sort_keys=True, ensure_ascii=False))