kindle manager
This commit is contained in:
1
backup/bk.info.data
Normal file
1
backup/bk.info.data
Normal file
File diff suppressed because one or more lines are too long
1
backup/bk.info.data.bk
Normal file
1
backup/bk.info.data.bk
Normal file
File diff suppressed because one or more lines are too long
@@ -84,10 +84,12 @@ b['1']['2'] = {'3':1} # OK
|
||||
## learn lesson
|
||||
|
||||
|
||||
---
|
||||
|
||||
# feature list
|
||||
- first abstract from kindle hard / local directory for different OS **done**
|
||||
- add GUI use QT **done**
|
||||
- use thread to check kindle connection status **XXXX**
|
||||
- use thread to check kindle connection status **done**
|
||||
- import function:
|
||||
- local **done**
|
||||
- kindle **done**
|
||||
@@ -101,7 +103,7 @@ b['1']['2'] = {'3':1} # OK
|
||||
- onenote
|
||||
- txt **done**
|
||||
- markdown **done**
|
||||
- easily coly filter notes to clipboard
|
||||
- easily copy filter notes to clipboard
|
||||
- implement command line based on [argparse](https://www.jianshu.com/p/a41fbd4919f8)
|
||||
- mobi / epub reader **XXXX**
|
||||
- import .azw3/.epub/.mobi file to kindle
|
||||
@@ -117,3 +119,4 @@ b['1']['2'] = {'3':1} # OK
|
||||
- sync modify to kindle device
|
||||
- compare parse html info with xpath & beautisoap & regex
|
||||
|
||||
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 5.8 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 9.7 KiB |
5
kman.py
5
kman.py
@@ -71,8 +71,9 @@ DEBUG = 1 # 0 - INFO; 1 - DEBUG
|
||||
LOG2FILE = 1 # 0 - to stdio; 1 - to file
|
||||
LOGFILE = 'log'
|
||||
DELIMITER= '|'
|
||||
BACKUPNOTEFN = './backup/bk.note.data'
|
||||
BACKUPWORDFN = './backup/bk.word.data'
|
||||
BACKUPNOTEFN = './backup/bk.note.data' # kindle notes
|
||||
BACKUPWORDFN = './backup/bk.word.data' # kindle words
|
||||
BACKUPINFOFN = './backup/bk.info.data' # book information from douban/amazon
|
||||
#HEADER = {0:'type',1:'bookname',2:'author',3:'position',4:'date',5:'content'}
|
||||
|
||||
# log info
|
||||
|
||||
61
kmanapp.py
61
kmanapp.py
@@ -89,6 +89,29 @@ class kmanWindow(QMainWindow):
|
||||
[self.filter_books, self.filter_list] = self.km.filter_clips(self.books_data)
|
||||
#self.filter_list = self.km.filter_words(self.words_data)
|
||||
|
||||
# initial books information which grab from douban or amazon
|
||||
# if the information exist in backup file, initial with this file,
|
||||
# and grap new book's information from douban
|
||||
# else grap all book information from douban
|
||||
self.books_info = defaultdict(dict)
|
||||
try:
|
||||
if os.path.exists(BACKUPINFOFN):
|
||||
self.books_info = self.km.json2dict(BACKUPINFOFN)
|
||||
increase_book_list = self.check_increase_books(self.books_data, self.books_info)
|
||||
if len(increase_book_list) > 0:
|
||||
trd = threading.Thread(target=self.grab_books_info, args=(increase_book_list,))
|
||||
trd.setDaemon(True)
|
||||
trd.start()
|
||||
else:
|
||||
booklist = list(self.books_data.keys())
|
||||
trd = threading.Thread(target=self.grab_books_info, args=(book_list,))
|
||||
trd.setDaemon(True)
|
||||
trd.start()
|
||||
except Exception as e:
|
||||
print(e)
|
||||
finally:
|
||||
pass
|
||||
|
||||
self.fill_treeview()
|
||||
self.refresh_ui_component(comp=1)
|
||||
|
||||
@@ -126,6 +149,20 @@ class kmanWindow(QMainWindow):
|
||||
ui.tableView.verticalHeader().hide()
|
||||
ui.tableView.setModel(self.ui.tablemodel)
|
||||
|
||||
def check_increase_books(self, bks, bksinfo):
|
||||
new_list = list(bks.keys()) # kindle's books with note
|
||||
new_list = [re.split(r'[\((\-\::_\s]',nn.strip())[0] for nn in new_list]
|
||||
last_list = list(bksinfo.keys()) # grab book information last time
|
||||
increase_list = []
|
||||
for nn in new_list:
|
||||
flag = 0
|
||||
for gg in last_list:
|
||||
if nn in gg: flag = 1
|
||||
if flag == 0:
|
||||
increase_list.append(nn)
|
||||
|
||||
return increase_list
|
||||
|
||||
def add_ui_component(self):
|
||||
self.ui.searchComboBox.addItems([u'ALL',u'BOOKNAME',u'CONTENT',u'AUTHOR'])
|
||||
self.ui.treeView.resize(200,200)
|
||||
@@ -514,26 +551,32 @@ class kmanWindow(QMainWindow):
|
||||
r = msgBox.exec()
|
||||
|
||||
# backup file when kman closed
|
||||
# read backup file when kman start
|
||||
# so we can read backup file when kman start
|
||||
def closeEvent(self, e):
|
||||
with open(BACKUPNOTEFN, 'w', encoding='utf8', errors='ignore') as fw:
|
||||
fw.write(self.km.dict2json(self.books_data))
|
||||
with open(BACKUPWORDFN, 'w', encoding='utf8', errors='ignore') as fw:
|
||||
fw.write(self.km.dict2json(self.words_data))
|
||||
with open(BACKUPINFOFN, 'w', encoding='utf8', errors='ignore') as fw:
|
||||
fw.write(self.km.dict2json(self.books_info))
|
||||
|
||||
# stop check thread
|
||||
self.flag = False
|
||||
|
||||
def grab_all_book_info(self):
|
||||
def grab_books_info(self, booklist):
|
||||
|
||||
for bkname in self.books_data.keys():
|
||||
bks_info = {}
|
||||
for bkname in booklist:
|
||||
bkname = re.split(r'[\((\-\::_\s]',bkname.strip())[0]
|
||||
print(bkname)
|
||||
bkinfo = self.spide.grab_book_info(bkname)
|
||||
filter_bkinfo = self.spide.filter_spide_book(bkinfo)
|
||||
bks_info.update(filter_bkinfo)
|
||||
if filter_bkinfo:
|
||||
self.spide.down_book_img(filter_bkinfo)
|
||||
|
||||
return self.books_info.update(bks_info)
|
||||
|
||||
# thanks Martin Fitzpatrick ^_^
|
||||
# https://www.learnpyqt.com/courses/model-views/qtableview-modelviews-numpy-pandas/
|
||||
class nTableModel(QAbstractTableModel):
|
||||
@@ -576,9 +619,19 @@ if __name__ == "__main__":
|
||||
#kmw.showFullScreen()
|
||||
kmw.show()
|
||||
|
||||
trd = threading.Thread(target=kmw.grab_all_book_info)
|
||||
"""
|
||||
# move to __init__()
|
||||
try:
|
||||
booklist = self.books_data.keys()
|
||||
trd = threading.Thread(target=kmw.grab_books_info, args=(booklist,))
|
||||
trd.setDaemon(True)
|
||||
trd.start()
|
||||
except Exception as e:
|
||||
print(e)
|
||||
pass
|
||||
finally:
|
||||
pass
|
||||
"""
|
||||
|
||||
# loop check kindle is connected or not
|
||||
# BUG to be implement XXXX
|
||||
|
||||
12
parseweb.py
12
parseweb.py
@@ -182,20 +182,17 @@ class bookInfoSpide():
|
||||
mparams['k'] = mbkn
|
||||
|
||||
try:
|
||||
s = requests.Session()
|
||||
s.header = mheaders
|
||||
s.params = mparams
|
||||
r = s.get(murl)
|
||||
session = requests.Session()
|
||||
session.header = mheaders
|
||||
session.params = mparams
|
||||
r = session.get( url=murl, headers=mheaders, params=mparams)
|
||||
#r = requests.get( url=murl, headers=mheaders, params=mparams)
|
||||
|
||||
except requests.exceptions.ConnectionError:
|
||||
print('ConnectionError -- please wait 3 seconds')
|
||||
time.sleep(3)
|
||||
|
||||
except requests.exceptions.ChunkedEncodingError:
|
||||
print('ChunkedEncodingError -- please wait 3 seconds')
|
||||
time.sleep(3)
|
||||
|
||||
except:
|
||||
print('Unfortunitely -- An Unknow Error Happened, Please wait 3 seconds')
|
||||
time.sleep(3)
|
||||
@@ -361,7 +358,6 @@ class bookInfoSpide():
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
spide = bookInfoSpide()
|
||||
|
||||
Reference in New Issue
Block a user