kindle manager

This commit is contained in:
gavin
2020-06-26 11:26:19 +08:00
parent d7672d9380
commit 6eac75b852
28 changed files with 4820 additions and 26731 deletions

35
kman.py
View File

@@ -8,6 +8,7 @@
#########################################################
import re
import sys
import os
import io
import json
@@ -65,15 +66,16 @@ LASTLINE = '=========='
NTPREF = '--CG注:'
CLIPFN = 'My Clippings.txt'
WORDFN = 'vocab.db'
CLIPPATH = './'
OUTPREF = './clip'
CURRPATH = os.path.dirname(os.path.realpath(sys.argv[0]))
OUTPREF = os.path.join(CURRPATH,'CLIP')
DEBUG = 1 # 0 - INFO; 1 - DEBUG
LOG2FILE = 1 # 0 - to stdio; 1 - to file
LOGFILE = 'log'
DELIMITER= '|'
BACKUPNOTEFN = './backup/bk.note.data' # kindle notes
BACKUPWORDFN = './backup/bk.word.data' # kindle words
BACKUPINFOFN = './backup/bk.info.data' # book information from douban/amazon
BACKUPFOLDER = os.path.join(CURRPATH,'backup')
BACKUPNOTEFN = os.path.join(BACKUPFOLDER,'bk.note.data') # kindle notes
BACKUPWORDFN = os.path.join(BACKUPFOLDER,'bk.word.data') # kindle words
BACKUPINFOFN = os.path.join(BACKUPFOLDER,'bk.info.data') # book information from douban/amazon
#HEADER = {0:'type',1:'bookname',2:'author',3:'position',4:'date',5:'content'}
# log info
@@ -119,6 +121,7 @@ r'''
class kMan:
def __init__(self, parent=None):
self.hlnum = 0
self.ntnum = 0
self.refleshtime = '2020/10/10 10:00:00'
@@ -130,7 +133,7 @@ class kMan:
kp = self.get_kindle_path()
if not kp:
s2 = u'Disconnected ({})'.format(CLIPPATH+CLIPFN)
s2 = u'Disconnected ({})'.format(os.path.join(CURRPATH,CLIPFN))
else:
with open(kp+'/system/version.txt' , 'r', encoding='utf8', errors='ignore') as f:
s2 = u'Connected ({}) version {}'.format(kp,f.read().strip())
@@ -597,7 +600,7 @@ class kMan:
return False
def import_clips(self, fp=(CLIPPATH+CLIPFN)):
def import_clips(self, fp=os.path.join(CURRPATH, CLIPFN)):
"""import clips from local file or kindle
4 lines for each section seperated with '======='
so read 4 lines before '======='
@@ -616,6 +619,8 @@ class kMan:
path = fn
"""
if not os.path.exists(fp): return {}
# loop to fill books dict
with open(fp, 'r', encoding='utf8', errors='ignore') as f:
bks = defaultdict(dict)
@@ -670,7 +675,7 @@ class kMan:
return self.drop_duplicate(bks)
# words operations
def import_words(self, fp=(CLIPPATH+WORDFN)):
def import_words(self, fp=(os.path.join(CURRPATH,WORDFN))):
"""import words from local file or kindle
vocab.db -> tables: BOOK_INFO, LOOKUPS, WORDS
@@ -784,6 +789,19 @@ class kMan:
return [nu, bk_wd_num]
class Util:
def __init__(self, parent=None):
pass
@staticmethod
def get_app_path():
"""Returns the base application path."""
if hasattr(sys, 'frozen'):
# Handles PyInstaller
return os.path.dirname(sys.executable) # 使用pyinstaller打包后的exe目录
return os.path.dirname(__file__) # 没打包前的py目录
if __name__=='__main__':
#books = defaultdict(dict)
km = kMan()
@@ -815,4 +833,3 @@ if __name__=='__main__':
# print data with json format
logger.debug(json.dumps(books, indent=4, sort_keys=True, ensure_ascii=False))