kindle manager

This commit is contained in:
gavin
2020-06-12 23:33:35 +08:00
parent 43c602d8d6
commit 8dbd2357b2
17 changed files with 3570 additions and 103 deletions

View File

@@ -8,11 +8,22 @@
#########################################################
import unittest
import json
from collections import defaultdict
from kman import *
# log info
logger = logging.getLogger()
#formatter = logging.Formatter
# ('%(asctime)s - %(pathname)s[line:%(lineno)d] - %(levelname)s: %(message)s')
formatter = logging.Formatter('')
handler = logging.FileHandler('debug')
handler.setFormatter(formatter)
logger.addHandler(handler)
logger.setLevel(logging.DEBUG)
class TestKman(unittest.TestCase):
# initial
def setUp(self):
@@ -175,32 +186,52 @@ class TestKman(unittest.TestCase):
t_books = self.cre_tbooks()
t_books_remove_nt = self.km.add_note_to_highlight(t_books)
self.assertEqual((t_books_remove_nt['薛兆丰经济学讲义']['1']['content']).replace('\n',''),\
'边际就是“新增”带来的“新增”。'+NTPREF+ '山寨 假货 问题')
'边际就是“新增”带来的“新增”。'+NTPREF+ '山寨 假货 问题')
def test_get_kindle_path(self):
kp = self.km.get_kindle_path()
s = u"kindle disconnected" if not kp else u"kindle connected {}".format(kp)
print(s)
def test_get_bookname_num(self):
t_books = self.cre_tbooks()
[nu, bn] = self.km.get_bookname_num(t_books)
self.assertEqual(bn['薛兆丰经济学讲义'],2)
def test_get_author_num(self):
def test_get_author_num(self):
t_books = self.cre_tbooks()
[nu, bn] = self.km.get_author_num(t_books)
self.assertEqual(bn['薛兆丰'],2)
def test_filter_clips(self):
t_books = self.cre_tbooks()
# no filter
bn = self.km.filter_clips(t_books, '薛兆丰', 0)
logger.debug('========== 1 ==========\n')
logger.debug(json.dumps(bn, indent=2, ensure_ascii=False))
print('filter 0 \n',bn)
bn = {}
# by bookname
bn = self.km.filter_clips(t_books, '枪炮、病菌与钢铁 : 人类社会的命运 (世纪人文系列丛书·开放人文)', 1)
logger.debug('========== 2 ==========\n')
logger.debug(json.dumps(bn, indent=2, ensure_ascii=False))
bn = {}
# by author
bn = self.km.filter_clips(t_books, '贾雷德·戴蒙德', 2)
logger.debug('========== 3 ==========\n')
logger.debug(json.dumps(bn, indent=2, ensure_ascii=False))
bn = {}
# test import words & filter words
def test_import_words(self):
import pprint
[bookinfo, lookups, words] = self.km.import_words(fp=(CLIPPATH+WORDFN))
# how to beauty print to logger file
logger.debug('========== 4 ==========\n')
logger.debug(json.dumps(bookinfo, indent=2, ensure_ascii=False))
logger.debug('========== 5 ==========\n')
logger.debug(json.dumps(lookups, indent=2, ensure_ascii=False))
logger.debug('========== 6 ==========\n')
logger.debug(json.dumps(words, indent=2, ensure_ascii=False))