From b57297a443e9989d298fd3c7512938ee1779f34d Mon Sep 17 00:00:00 2001 From: gavin Date: Thu, 4 Jun 2020 09:27:14 +0800 Subject: [PATCH] kindle manager --- kman.py | 23 ++++++++++++++--------- kmanapp.py | 8 ++++++-- mainwindow.ui | 4 ++-- searchtitle.md | 3 +++ xx | 1 + 5 files changed, 26 insertions(+), 13 deletions(-) create mode 100644 searchtitle.md create mode 100644 xx diff --git a/kman.py b/kman.py index 202c896..aed506f 100644 --- a/kman.py +++ b/kman.py @@ -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)) - - diff --git a/kmanapp.py b/kmanapp.py index 1115ff3..245399b 100644 --- a/kmanapp.py +++ b/kmanapp.py @@ -3,6 +3,7 @@ import sys from PySide2.QtWidgets import QApplication from PySide2.QtWidgets import QMainWindow from mainwindow import Ui_MainWindow +from kman import * class kmanWindow(QMainWindow): """ @@ -18,8 +19,10 @@ class kmanWindow(QMainWindow): ui.setupUi(self) self.ui = ui + books = import_clips() + # connect action to slot functions - ui.actionimportkindle.triggered.connect(lambda: self.importkindle()) + ui.actionimportkindle.triggered.connect(lambda: self.importkindle(books)) ui.actionimportlocal.triggered.connect(lambda: self.importlocal()) ui.actionconfig.triggered.connect(lambda: self.config()) ui.actionwords.triggered.connect(lambda: self.words()) @@ -29,8 +32,9 @@ class kmanWindow(QMainWindow): ui.actionflush.triggered.connect(lambda: self.flush()) # define slot functions - def importkindle(self): + def importkindle(self,bks): print("call slot importkindle()") + print(bks) pass def importlocal(self): diff --git a/mainwindow.ui b/mainwindow.ui index ee99b97..1bf3d1b 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -168,10 +168,10 @@ icons/refresh.pngicons/refresh.png - flush + refresh - flush import file + refresh import file/quick import from kindle diff --git a/searchtitle.md b/searchtitle.md new file mode 100644 index 0000000..60a4f4e --- /dev/null +++ b/searchtitle.md @@ -0,0 +1,3 @@ +TYPE|BOOKNAME|AUTHOR|MARKTIME|CONTENT +--|--|--|--|-- +HL|薛兆丰经济学讲义 |薛兆丰|2020/1/13 8:11:05|么到底什么叫边际?边际就是“新增”带来的“新增”。 例如,边际成本就是每新增一个单位产品所需要付出的新增成本;边际收入是每多卖一个产品能够带来的新增收入;边际产量是每新增一份投入所带来的新增产量;边际效用是每消耗一个单位的商品所能带来的新增享受。 diff --git a/xx b/xx new file mode 100644 index 0000000..f91e546 --- /dev/null +++ b/xx @@ -0,0 +1 @@ +{"\u859b\u5146\u4e30\u7ecf\u6d4e\u5b66\u8bb2\u4e49 ": {"author": "\u859b\u5146\u4e30", "1": {"type": "HL", "position": "1408-1410", "day": "2020\u5e741\u670813\u65e5", "week": "\u661f\u671f\u4e00", "meridiem": "\u4e0a\u5348", "time": "8:11:05", "content": "\u4e48\u5230\u5e95\u4ec0\u4e48\u53eb\u8fb9\u9645\uff1f\u8fb9\u9645\u5c31\u662f\u201c\u65b0\u589e\u201d\u5e26\u6765\u7684\u201c\u65b0\u589e\u201d\u3002 \u4f8b\u5982\uff0c\u8fb9\u9645\u6210\u672c\u5c31\u662f\u6bcf\u65b0\u589e\u4e00\u4e2a\u5355\u4f4d\u4ea7\u54c1\u6240\u9700\u8981\u4ed8\u51fa\u7684\u65b0\u589e\u6210\u672c\uff1b\u8fb9\u9645\u6536\u5165\u662f\u6bcf\u591a\u5356\u4e00\u4e2a\u4ea7\u54c1\u80fd\u591f\u5e26\u6765\u7684\u65b0\u589e\u6536\u5165\uff1b\u8fb9\u9645\u4ea7\u91cf\u662f\u6bcf\u65b0\u589e\u4e00\u4efd\u6295\u5165\u6240\u5e26\u6765\u7684\u65b0\u589e\u4ea7\u91cf\uff1b\u8fb9\u9645\u6548\u7528\u662f\u6bcf\u6d88\u8017\u4e00\u4e2a\u5355\u4f4d\u7684\u5546\u54c1\u6240\u80fd\u5e26\u6765\u7684\u65b0\u589e\u4eab\u53d7\u3002"}, "lines": 1}} \ No newline at end of file