Last active
June 2, 2019 04:00
-
-
Save guerbai/f8e6df3fec2a14152d2a6b1b3088585d to your computer and use it in GitHub Desktop.
kindle标注行按书名整理
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding:utf-8 -*- | |
from collections import defaultdict | |
shinewords = open('cli.txt','r').read().decode('utf-8') | |
section = shinewords.strip().split("==========\r\n") | |
books = defaultdict(lambda : "") | |
for i in section: | |
try: | |
i = i.split('\n') | |
books[i[0]] += i[3]+'\n\n' | |
#最后一个分割为文档结束符,它并没有前面全部正常 | |
except IndexError: | |
pass | |
with open('note.txt','wb') as f: | |
for i in books: | |
f.write(i.encode('utf-8') + '\n\n' + books[i].encode('utf-8') + '==========\n') | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment