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
|
## learn lesson
|
||||||
|
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
# feature list
|
# feature list
|
||||||
- first abstract from kindle hard / local directory for different OS **done**
|
- first abstract from kindle hard / local directory for different OS **done**
|
||||||
- add GUI use QT **done**
|
- add GUI use QT **done**
|
||||||
- use thread to check kindle connection status **XXXX**
|
- use thread to check kindle connection status **done**
|
||||||
- import function:
|
- import function:
|
||||||
- local **done**
|
- local **done**
|
||||||
- kindle **done**
|
- kindle **done**
|
||||||
@@ -101,7 +103,7 @@ b['1']['2'] = {'3':1} # OK
|
|||||||
- onenote
|
- onenote
|
||||||
- txt **done**
|
- txt **done**
|
||||||
- markdown **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)
|
- implement command line based on [argparse](https://www.jianshu.com/p/a41fbd4919f8)
|
||||||
- mobi / epub reader **XXXX**
|
- mobi / epub reader **XXXX**
|
||||||
- import .azw3/.epub/.mobi file to kindle
|
- import .azw3/.epub/.mobi file to kindle
|
||||||
@@ -117,3 +119,4 @@ b['1']['2'] = {'3':1} # OK
|
|||||||
- sync modify to kindle device
|
- sync modify to kindle device
|
||||||
- compare parse html info with xpath & beautisoap & regex
|
- 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
|
LOG2FILE = 1 # 0 - to stdio; 1 - to file
|
||||||
LOGFILE = 'log'
|
LOGFILE = 'log'
|
||||||
DELIMITER= '|'
|
DELIMITER= '|'
|
||||||
BACKUPNOTEFN = './backup/bk.note.data'
|
BACKUPNOTEFN = './backup/bk.note.data' # kindle notes
|
||||||
BACKUPWORDFN = './backup/bk.word.data'
|
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'}
|
#HEADER = {0:'type',1:'bookname',2:'author',3:'position',4:'date',5:'content'}
|
||||||
|
|
||||||
# log info
|
# log info
|
||||||
|
|||||||
65
kmanapp.py
65
kmanapp.py
@@ -89,6 +89,29 @@ class kmanWindow(QMainWindow):
|
|||||||
[self.filter_books, self.filter_list] = self.km.filter_clips(self.books_data)
|
[self.filter_books, self.filter_list] = self.km.filter_clips(self.books_data)
|
||||||
#self.filter_list = self.km.filter_words(self.words_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.fill_treeview()
|
||||||
self.refresh_ui_component(comp=1)
|
self.refresh_ui_component(comp=1)
|
||||||
|
|
||||||
@@ -126,6 +149,20 @@ class kmanWindow(QMainWindow):
|
|||||||
ui.tableView.verticalHeader().hide()
|
ui.tableView.verticalHeader().hide()
|
||||||
ui.tableView.setModel(self.ui.tablemodel)
|
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):
|
def add_ui_component(self):
|
||||||
self.ui.searchComboBox.addItems([u'ALL',u'BOOKNAME',u'CONTENT',u'AUTHOR'])
|
self.ui.searchComboBox.addItems([u'ALL',u'BOOKNAME',u'CONTENT',u'AUTHOR'])
|
||||||
self.ui.treeView.resize(200,200)
|
self.ui.treeView.resize(200,200)
|
||||||
@@ -514,26 +551,32 @@ class kmanWindow(QMainWindow):
|
|||||||
r = msgBox.exec()
|
r = msgBox.exec()
|
||||||
|
|
||||||
# backup file when kman closed
|
# backup file when kman closed
|
||||||
# read backup file when kman start
|
# so we can read backup file when kman start
|
||||||
def closeEvent(self, e):
|
def closeEvent(self, e):
|
||||||
with open(BACKUPNOTEFN, 'w', encoding='utf8', errors='ignore') as fw:
|
with open(BACKUPNOTEFN, 'w', encoding='utf8', errors='ignore') as fw:
|
||||||
fw.write(self.km.dict2json(self.books_data))
|
fw.write(self.km.dict2json(self.books_data))
|
||||||
with open(BACKUPWORDFN, 'w', encoding='utf8', errors='ignore') as fw:
|
with open(BACKUPWORDFN, 'w', encoding='utf8', errors='ignore') as fw:
|
||||||
fw.write(self.km.dict2json(self.words_data))
|
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
|
# stop check thread
|
||||||
self.flag = False
|
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]
|
bkname = re.split(r'[\((\-\::_\s]',bkname.strip())[0]
|
||||||
print(bkname)
|
print(bkname)
|
||||||
bkinfo = self.spide.grab_book_info(bkname)
|
bkinfo = self.spide.grab_book_info(bkname)
|
||||||
filter_bkinfo = self.spide.filter_spide_book(bkinfo)
|
filter_bkinfo = self.spide.filter_spide_book(bkinfo)
|
||||||
|
bks_info.update(filter_bkinfo)
|
||||||
if filter_bkinfo:
|
if filter_bkinfo:
|
||||||
self.spide.down_book_img(filter_bkinfo)
|
self.spide.down_book_img(filter_bkinfo)
|
||||||
|
|
||||||
|
return self.books_info.update(bks_info)
|
||||||
|
|
||||||
# thanks Martin Fitzpatrick ^_^
|
# thanks Martin Fitzpatrick ^_^
|
||||||
# https://www.learnpyqt.com/courses/model-views/qtableview-modelviews-numpy-pandas/
|
# https://www.learnpyqt.com/courses/model-views/qtableview-modelviews-numpy-pandas/
|
||||||
class nTableModel(QAbstractTableModel):
|
class nTableModel(QAbstractTableModel):
|
||||||
@@ -576,9 +619,19 @@ if __name__ == "__main__":
|
|||||||
#kmw.showFullScreen()
|
#kmw.showFullScreen()
|
||||||
kmw.show()
|
kmw.show()
|
||||||
|
|
||||||
trd = threading.Thread(target=kmw.grab_all_book_info)
|
"""
|
||||||
trd.setDaemon(True)
|
# move to __init__()
|
||||||
trd.start()
|
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
|
# loop check kindle is connected or not
|
||||||
# BUG to be implement XXXX
|
# BUG to be implement XXXX
|
||||||
|
|||||||
12
parseweb.py
12
parseweb.py
@@ -182,20 +182,17 @@ class bookInfoSpide():
|
|||||||
mparams['k'] = mbkn
|
mparams['k'] = mbkn
|
||||||
|
|
||||||
try:
|
try:
|
||||||
s = requests.Session()
|
session = requests.Session()
|
||||||
s.header = mheaders
|
session.header = mheaders
|
||||||
s.params = mparams
|
session.params = mparams
|
||||||
r = s.get(murl)
|
r = session.get( url=murl, headers=mheaders, params=mparams)
|
||||||
#r = requests.get( url=murl, headers=mheaders, params=mparams)
|
#r = requests.get( url=murl, headers=mheaders, params=mparams)
|
||||||
|
|
||||||
except requests.exceptions.ConnectionError:
|
except requests.exceptions.ConnectionError:
|
||||||
print('ConnectionError -- please wait 3 seconds')
|
print('ConnectionError -- please wait 3 seconds')
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
|
|
||||||
except requests.exceptions.ChunkedEncodingError:
|
except requests.exceptions.ChunkedEncodingError:
|
||||||
print('ChunkedEncodingError -- please wait 3 seconds')
|
print('ChunkedEncodingError -- please wait 3 seconds')
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
|
|
||||||
except:
|
except:
|
||||||
print('Unfortunitely -- An Unknow Error Happened, Please wait 3 seconds')
|
print('Unfortunitely -- An Unknow Error Happened, Please wait 3 seconds')
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
@@ -361,7 +358,6 @@ class bookInfoSpide():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
spide = bookInfoSpide()
|
spide = bookInfoSpide()
|
||||||
|
|||||||
Reference in New Issue
Block a user