├── KindleSorted.py ├── README.md ├── Weread.py ├── koreader标注(.json)转markdown或hexo(.md).py ├── oldFileBackup ├── BooxCloudOnenoteOS3.1 NotWorking.py ├── BooxLocalInternational.py ├── BooxLocalInternational_anotherVersion.py ├── BooxLocalOS3.1.py ├── BooxOS2.3.py ├── ConvertToEPUB3.2Footnote.py ├── KOReaderJsonALL.py ├── KOReaderJsonALLtoEachBook.py ├── MoonReaderProToMrexpt.py ├── MoonReaderProToMrexptForHexo.py ├── MoonReaderProToTXT.py └── MoonReaderProToTXTbyQQ.py ├── 文石BOOXOS4.0标注(.txt)转markdown或hexo(.md).py └── 静读天下专业版标注(.mrexpt)转markdown或hexo(.md).py /KindleSorted.py: -------------------------------------------------------------------------------- 1 | # -*- coding: UTF-8 -*- 2 | import sys 3 | import os 4 | import pathlib 5 | 6 | # Highlights format support in 20200313 7 | # support kindle , boox local and boox cloud 8 | # Programmed by Andy 9 | # v0.3 10 | 11 | def readfile(filename): 12 | #readfile 13 | with open(filename, mode='r', encoding='UTF-8') as file: 14 | filereadlines = file.readlines() 15 | #remove blank lines 16 | for i in filereadlines: 17 | if i == '\n': 18 | filereadlines.remove(i) 19 | #remove '\n' in line end 20 | for i in range(len(filereadlines)): 21 | filereadlines[i] = filereadlines[i].rstrip() 22 | return filereadlines 23 | 24 | def writefile(filename,filereadlines): 25 | #write file 26 | newfile = open(filename.with_suffix('.md'), mode='w', encoding='UTF-8') 27 | newfile.writelines(filereadlines) 28 | newfile.close() 29 | 30 | def converterFromKindleSorted(filename): 31 | #readfile 32 | filereadlines = readfile(filename) 33 | #get '==========' line number 34 | linenum = [-1] 35 | for i in range(len(filereadlines)): 36 | if '==========' in filereadlines[i]: 37 | linenum.append(i) 38 | #converter each highlight block to [][] 39 | newcontent = [] 40 | for i in range(len(linenum) - 1): 41 | eachcontent = [] 42 | for j in range(linenum[i] + 1, linenum[i + 1]): 43 | if filereadlines[j] != '': 44 | eachcontent.append(filereadlines[j]) 45 | newcontent.append(eachcontent) 46 | #format eachline to markdown 47 | #chapter,time,content style 48 | sortedcontent = {} 49 | for i in range(len(newcontent)): 50 | if newcontent[i][0] not in sortedcontent: 51 | if len(newcontent[i]) >= 3: 52 | sortedcontent[newcontent[i][0]]=[] 53 | sortedcontent[newcontent[i][0]].append([newcontent[i][1] , newcontent[i][2]]) 54 | elif newcontent[i][0] in sortedcontent: 55 | if len(newcontent[i]) >= 3: 56 | sortedcontent[newcontent[i][0]].append([newcontent[i][1] , newcontent[i][2]]) 57 | outputfile = ['[TOC]\n\n---\n\n'] 58 | for key in sortedcontent: 59 | outputfile.append('## ' + key + '\n\n') 60 | for j in range(len(sortedcontent[key])): 61 | outputfile.append('*' + sortedcontent[key][j][0] + '*\n\n') 62 | outputfile.append('> ' + sortedcontent[key][j][1] + '\n\n') 63 | outputfile.append('---\n\n') 64 | outputfile[-1] = '---' 65 | #write file 66 | writefile(filename,outputfile) 67 | 68 | def converterFromKindleNatured(filename): 69 | #readfile 70 | filereadlines = readfile(filename) 71 | #get '==========' line number 72 | linenum = [-1] 73 | for i in range(len(filereadlines)): 74 | if '==========' in filereadlines[i]: 75 | linenum.append(i) 76 | outputfile = [] 77 | #converter each highlight block to [][] 78 | newcontent = [] 79 | for i in range(len(linenum) - 1): 80 | eachcontent = [] 81 | for j in range(linenum[i] + 1, linenum[i + 1]): 82 | if filereadlines[j] != '': 83 | eachcontent.append(filereadlines[j]) 84 | newcontent.append(eachcontent) 85 | #format eachline to markdown 86 | #chapter,time,content style 87 | for i in range(len(newcontent)): 88 | outputfile.append('## ' + newcontent[i][0] + '\n\n') 89 | outputfile.append('*' + newcontent[i][1] + '*\n\n') 90 | if len(newcontent[i]) >= 3: 91 | outputfile.append('> ' + newcontent[i][2] + '\n\n') 92 | outputfile.append('---\n\n') 93 | outputfile[-1] = '---' 94 | #write file 95 | writefile(filename,outputfile) 96 | 97 | def main(filename): 98 | #read file 99 | file = open(filename, mode='r', encoding='UTF-8') 100 | firstline = file.readline() 101 | 102 | if (type(filename).__name__ == 'str'): 103 | filename = Path(filename) 104 | #Judge highlights from cloud note:onenote and evernote (False) or boox local storage (True) or kindle My Clippings.txt 105 | if filename.name == 'My Clippings.txt' and os.path.basename(__file__) == 'Kindle.py': 106 | converterFromKindleNatured(filename) 107 | elif filename.name == 'My Clippings.txt' and os.path.basename(__file__) == 'KindleSorted.py': 108 | converterFromKindleSorted(filename) 109 | 110 | if __name__ == '__main__': 111 | if len(sys.argv) == 1: 112 | for filenames in pathlib.Path('./').rglob('*.txt'): 113 | main(filenames) 114 | elif len(sys.argv) >= 2: 115 | for i in range(1 , len(sys.argv)): 116 | main(sys.argv[i]) -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## 博客原文 2 | 3 | [静读天下MoonReaderPro,Kindle,KOReader,微信读书Weread标注转换为Markdown格式](https://andi.wang/2021/03/15/文石Boox,Kindle,静读天下专业版,微信读书,KOReader的标注转换为Markdown格式) 4 | 5 | [部分书籍标注展示,多数使用MoonReaderProToMrexptForHexo.py](https://andi.wang/categories/%E8%AF%BB%E4%B9%A6%E7%AC%94%E8%AE%B0/) 6 | 7 | 8 | ## 静读天下MoonReaderPro,Kindle,KOReader,微信读书Weread标注转换为Markdown格式 9 | 10 | ### 基本用法(win10) 11 | 12 | 安装python:[https://www.python.org](https://www.python.org),复制你的标注到文件夹,运行对应的py文件或者拖拽标注文件的py上 13 | 14 | ### 静读天下专业版 15 | 16 | 书签导出时选导出到文件,静读天下专业版标注(.mrexpt)转markdown或hexo(.md).py 17 | 18 | 静读天下专业版中,书签,导出到文件,复制.mrexpt文件,拖拽文件夹或.mrexpt到.py文件上 19 | 20 | 静读天下专业版标注(.mrexpt)转hexo博客文章(.md).py,转换后的文件可以直接在Hexo博客里使用,'toHexoMode': False时也可以转换成普通的markdown格式 21 | 22 | 文件内CONFIG内可以设置:博客的标签,分类,主页显示的标注数量,按标注在书中的先后顺序或按标注添加的时间顺序 23 | 24 | ### 文石设备 25 | 26 | 2025.03.17更新BOOXOS 4.0脚本,文石BOOXOS4.0标注(.txt)转markdown或hexo(.md).py 27 | 28 | 导出txt的方法:boox系统中阅读某本书,点击中间,左下目录,上方第三个按钮,左下角圆圈全选,右边按钮,导出到本地 29 | 30 | ### KOReader 31 | 32 | koreader标注(.json)转markdown或hexo(.md).py 33 | 34 | 导出koreader标注的方法:菜单第四项工具,导出标注,选择格式和服务,json。导出标注,导出本书所有笔记。 35 | 36 | 导出后的json文件位置在根目录koreader\clipboard 37 | 38 | koreader-android-arm64-v2025.04版本测试通过 39 | 40 | ### Kindle 41 | 42 | 自动检测到My Clippings.txt 43 | 44 | *如果你想保留原来的标注顺序,KindleSorted.py 改成 Kindle.py* 45 | 46 | 标注文件测试成功在2020.03.13(My Clippings.txt 文件在 2018.10.14 生成) 47 | 48 | 复制My Clippings.txt,运行KindleSorted.py 49 | 50 | ### 微信读书 51 | 52 | 我,笔记,书名,右上角,复制到剪贴板,复制到.txt文件中后运行WereadClippingsToMarkdown.py 53 | 54 | --- 55 | 56 | ## Kindle,Moon Reader pro,KOReader,Weread Clippings To Markdown 57 | 58 | *https://andi.wang/* 59 | 60 | **old english translation, not update** 61 | 62 | **Basic usage(win10)** 63 | 64 | install python:[https://www.python.org/ftp/python/3.11.4/python-3.11.4-amd64.exe](https://www.python.org/ftp/python/3.11.4/python-3.11.4-amd64.exe),copy your clipping file to folder,run .py or drag your file onto .py 65 | 66 | **Moon Reader pro** 67 | in bookmark, chose output to file(.mrexpt):MoonReaderProToMrexpt.py 68 | 69 | In moon reader pro,bookmark, output to file, copy .mrexpt, drag .mrexpt or folder onto MoonReaderProToMrexpt.py 70 | 71 | For Hexo blog, use MoonReaderProToMrexptForHexo.py 72 | 73 | in bookmark, chose share clipping(TXT):MoonReaderProToTXT.py 74 | 75 | copy contents to TXT file, same 76 | 77 | **Kindle** 78 | 79 | Auto detect kindle My Clippings.txt 80 | 81 | if you dont's want the clippings sorted as book. Change KindleSorted.py to Kindle.py 82 | 83 | origin clippings file tested in 2020.03.13(My Clippings.txt created in 2018.10.14) 84 | 85 | copy My Clippings.txt,run KindleSorted.py 86 | 87 | **weread** 88 | 89 | my,note,book,top right corner,copy to clipboard,copy contents to .txt and run WereadClippingsToMarkdown.py 90 | 91 | **KOReader** 92 | 93 | menu,Evernote,Export to local json files,Export all notes in your library,copy KOReaderClipping.json,drag .json or folder to KOReaderJsonALL.py. If you want each book a .md file,please run KOReaderJsonALLtoEachBook.py 94 | 95 | **Boox eink reader** 96 | 97 | **boox script maybe not work, device is sold, update not sure** 98 | 99 | if with no arguments, it convert all .txt file in the folder(include subs),origin .txt not deleted 100 | 101 | if with arguments, it only convert the file to .md 102 | 103 | origin clippings file tested succeed in 2020.03.13 104 | 105 | BooxLocalInternational.py for https://github.com/wangandi520/ClippingsToMarkdown/issues/1 106 | 107 | BooxLocalInternational_anotherVersion.py https://github.com/wangandi520/ClippingsToMarkdown/issues/2 108 | -------------------------------------------------------------------------------- /Weread.py: -------------------------------------------------------------------------------- 1 | # -*- coding: UTF-8 -*- 2 | import sys 3 | import os 4 | import pathlib 5 | import re 6 | 7 | # Highlights format support in 20200313 8 | # support kindle , boox local and boox cloud 9 | # Programmed by Andy 10 | # v0.3 11 | 12 | def readfile(filename): 13 | # readfile 14 | with open(filename, mode='r', encoding='UTF-8') as file: 15 | filereadlines = file.readlines() 16 | # remove blank lines 17 | for i in filereadlines: 18 | if i == '\n': 19 | filereadlines.remove(i) 20 | # remove '\n' in line end 21 | for i in range(len(filereadlines)): 22 | filereadlines[i] = filereadlines[i].rstrip() 23 | return filereadlines 24 | 25 | def writefile(filename,filereadlines): 26 | # write file 27 | newfile = open(filename.with_suffix('.md'), mode='w', encoding='UTF-8') 28 | newfile.writelines(filereadlines) 29 | newfile.close() 30 | 31 | def converterFromClipboard(filename): 32 | # readfile 33 | filereadlines = readfile(filename) 34 | 35 | #book title,author style 36 | outputfile = [] 37 | outputfile.append('# ' + filereadlines[0] + '\n\n') 38 | outputfile.append('**' + filereadlines[1] + '**\n\n') 39 | outputfile.append('*' + filereadlines[2] + '*\n\n---') 40 | #converter each highlight block to [][] 41 | for i in range(3, len(filereadlines)): 42 | if filereadlines[i].startswith('◆'): 43 | outputfile.append('---\n\n**' + filereadlines[i][2:] + '**\n\n') 44 | if filereadlines[i].startswith('>>'): 45 | outputfile.append('> ' + filereadlines[i][3:] + '\n\n') 46 | print(filereadlines[i]) 47 | #write file 48 | writefile(filename,outputfile) 49 | 50 | 51 | 52 | def main(filename): 53 | # read file 54 | file = open(filename, mode='r', encoding='UTF-8') 55 | firstline = file.readline() 56 | 57 | if (type(filename).__name__ == 'str'): 58 | filename = Path(filename) 59 | # Paste content from weread to *.txt 60 | converterFromClipboard(filename) 61 | 62 | if __name__ == '__main__': 63 | if len(sys.argv) == 1: 64 | for filenames in pathlib.Path('./').rglob('*.txt'): 65 | main(filenames) 66 | elif len(sys.argv) >= 2: 67 | for i in range(1 , len(sys.argv)): 68 | main(sys.argv[i]) 69 | -------------------------------------------------------------------------------- /koreader标注(.json)转markdown或hexo(.md).py: -------------------------------------------------------------------------------- 1 | # encoding:utf-8 2 | # https://github.com/wangandi520/ClippingsToMarkdown 3 | # Programmed by Andy 4 | # koreader-android-arm64-v2025.04 5 | # v0.2 6 | # 2025.05.05 7 | # 导出koreader标注的方法:菜单第四项工具,导出标注,选择格式和服务,json。导出标注,导出本书所有笔记。 8 | # 导出后的json文件位置在根目录koreader\clipboard 9 | # 转换出的markdown文件直接可以在hexo里使用,一般放在hexo\source\_posts文件夹里 10 | 11 | from pathlib import Path 12 | import sys 13 | import time 14 | import re 15 | import json 16 | import datetime 17 | 18 | # 把可以更改的设置都放在这里 19 | CONFIG = { 20 | 'toHexoMode': True, # True: 转换成hexo博客的格式,False: 转换成一般markdown格式 21 | 'tags': ['阅读', '标注', '读书笔记'], # hexo博客的标签 22 | 'categories': '读书笔记', # hexo博客的分类 23 | 'preview_notes': 2, # 主页显示的标注数量 24 | 'showChapterAndPage': False # True: 在标注中显示章节和页数,False: 不显示 25 | } 26 | 27 | def validFileName(oldFileName): 28 | # '/ \ : * ? " < > |' 29 | # 替换为下划线 30 | validChars = r"[\/\\\:\*\?\"\<\>\|]" 31 | newFileName = re.sub(validChars, "", oldFileName) 32 | return newFileName 33 | 34 | def readJsonFile(filename: Path) -> list[str]: 35 | with open(filename, mode='r', encoding='UTF-8') as file: 36 | return json.load(file) 37 | 38 | def readfile(filename: Path) -> list[str]: 39 | with open(filename, mode='r', encoding='UTF-8') as file: 40 | return [line.rstrip() for line in file] 41 | 42 | def writefile(filename: Path, filereadlines: list[str]) -> None: 43 | # 写入.md文件 44 | newfile = open(Path(filename).parent.joinpath(Path(filename).stem + '标注.md'), mode='w', encoding='UTF-8') 45 | newfile.writelines(filereadlines) 46 | newfile.close() 47 | print('完成:' + str(Path(filename).name)) 48 | 49 | def convertKoreaderJson(filename: Path) -> None: 50 | # 读取.json文件 51 | jsonData = readJsonFile(filename) 52 | print('处理:' + str(Path(filename).name)) 53 | outputContent = [] 54 | # hexo文章头部信息Front-matter,title,tags,categories,time 55 | if CONFIG['toHexoMode']: 56 | myFrontMatter = '---\ntitle: ' + jsonData['title'] + ' 标注\ntoc: true\ntags:\n- ' + '\n- '.join(CONFIG['tags']) + '\ncategories: \n- ' + CONFIG['categories'] + '\ndate: ' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + '\n---\n\n' 57 | else: 58 | myFrontMatter = '## ' + jsonData['entries'] + '\n\n' 59 | outputContent.append(myFrontMatter) 60 | outputContent.append('**共' + str(len(jsonData['entries'])) + '条标注**\n\n---') 61 | for myIndex in range(0, len(jsonData['entries'])): 62 | outputContent.append('\n\n> ' + jsonData['entries'][myIndex]['text'] + '\n\n') 63 | if 'note' in jsonData['entries'][myIndex] and jsonData['entries'][myIndex]['note'] != '': 64 | outputContent.append('**' + jsonData['entries'][myIndex]['note'] + '**\n\n') 65 | outputContent.append('*' + time.strftime("%Y.%m.%d %H:%M:%S", time.localtime(jsonData['entries'][myIndex]['time'])) + '*') 66 | # 章节和页数 67 | if CONFIG['showChapterAndPage']: 68 | outputContent.append('\n\n*' + jsonData['entries'][myIndex]['chapter'] + '章 ' + str(jsonData['entries'][myIndex]['page']) + '页*') 69 | # 在主页显示几条标注 70 | if myIndex == CONFIG['preview_notes'] - 1 and CONFIG['toHexoMode']: 71 | outputContent.append('\n\n') 72 | # 标注内容在同一章节内,只显示一条分割线 73 | if myIndex < len(jsonData['entries']) - 1 and jsonData['entries'][myIndex]['chapter'] != jsonData['entries'][myIndex + 1]['chapter']: 74 | outputContent.append('\n\n---') 75 | outputContent.append('\n\n---') 76 | # 在主页显示几条标注,显示2条myIndex == 1 77 | # 写入.md文件 78 | writefile(validFileName(filename.name), outputContent) 79 | 80 | def main(inputPath: list[str]) -> None: 81 | fileType = {'.json'} 82 | for eachPath in inputPath[1:]: 83 | eachPath = Path(eachPath) 84 | if Path.is_dir(eachPath): 85 | for eachFile in eachPath.glob('**/*'): 86 | if eachFile.suffix in fileType: 87 | convertKoreaderJson(eachFile) 88 | if Path.is_file(eachPath): 89 | if eachPath.suffix in fileType: 90 | convertKoreaderJson(eachPath) 91 | 92 | if __name__ == '__main__': 93 | try: 94 | if len(sys.argv) >= 2: 95 | main(sys.argv) 96 | else: 97 | print('请拖拽文件到本脚本,或者命令行运行时添加文件路径') 98 | except Exception as e: 99 | print(f"程序运行出错: {str(e)}") -------------------------------------------------------------------------------- /oldFileBackup/BooxCloudOnenoteOS3.1 NotWorking.py: -------------------------------------------------------------------------------- 1 | # -*- coding: UTF-8 -*- 2 | import sys 3 | import os 4 | import pathlib 5 | import re 6 | 7 | # Highlights format support in 20210407 8 | # support kindle , boox local and boox cloud 9 | # Programmed by Andy 10 | # v0.4 11 | 12 | def readfile(filename): 13 | #readfile 14 | with open(filename, mode='r', encoding='UTF-8') as file: 15 | filereadlines = file.readlines() 16 | #remove blank lines 17 | for i in filereadlines: 18 | if i == '\n': 19 | filereadlines.remove(i) 20 | #remove '\n' in line end 21 | for i in range(len(filereadlines)): 22 | filereadlines[i] = filereadlines[i].rstrip() 23 | return filereadlines 24 | 25 | def writefile(filename,filereadlines): 26 | #write file 27 | newfile = open(filename.with_suffix('.md'), mode='w', encoding='UTF-8') 28 | newfile.writelines(filereadlines) 29 | newfile.close() 30 | 31 | 32 | def convertFromCloud(filename): 33 | #readfile 34 | filereadlines = readfile(filename) 35 | #output 36 | outputfile = [] 37 | #title 38 | outputfile.append('# ' + filereadlines[0] + '\n\n') 39 | #author 40 | outputfile.append('**' + filereadlines[1] + '**\n\n---\n\n') 41 | #check time format 42 | timereg = r'(\d{4}-\d{1,2}-\d{1,2}\s\d{1,2}:\d{1,2}:\d{1,2})' 43 | indexnum = [] 44 | #get time line number in file 45 | for i in range(0,len(filereadlines)): 46 | if re.match(timereg,filereadlines[i]): 47 | indexnum.append(i) 48 | elif filereadlines[i].startswith('BOOX读书笔记来自'): 49 | indexnum.append(i + 1) 50 | section = [] 51 | #split into sectionitem 52 | for i in range(0,len(indexnum) - 1): 53 | sectionitem = [] 54 | for j in range(indexnum[i] - 1,indexnum[i + 1] - 1): 55 | if not filereadlines[indexnum[i] - 1].startswith('注 |') and filereadlines[indexnum[i] + 1] != filereadlines[indexnum[i] - 1]: 56 | sectionitem.append(filereadlines[j]) 57 | section.append(sectionitem) 58 | print(section[1]) 59 | for i in section: 60 | outputfile.append('**' + i[0] + '**\n\n') 61 | outputfile.append('*' + i[1] + '*\n\n') 62 | j = 2 63 | while j < len(i): 64 | if i[j].startswith('注 |'): 65 | outputfile.append('[评论] ' + i[j][4:] + '\n\n') 66 | else: 67 | outputfile.append('> ' + i[j] + '\n\n') 68 | j = j + 1 69 | outputfile.append('---\n\n') 70 | outputfile.append('*' + filereadlines[-1] + '*\n') 71 | #write file 72 | writefile(filename,outputfile) 73 | 74 | def main(filename): 75 | #read file 76 | file = open(filename, mode='r', encoding='UTF-8') 77 | firstline = file.readline() 78 | 79 | if (type(filename).__name__ == 'str'): 80 | filename = Path(filename) 81 | #Judge highlights from cloud note:onenote and evernote (False) or boox local storage (True) or kindle My Clippings.txt 82 | if filename.name != 'My Clippings.txt': 83 | convertFromCloud(filename) 84 | 85 | if __name__ == '__main__': 86 | if len(sys.argv) == 1: 87 | for filenames in pathlib.Path('./').rglob('*.txt'): 88 | main(filenames) 89 | elif len(sys.argv) >= 2: 90 | for i in range(1 , len(sys.argv)): 91 | main(sys.argv[i]) 92 | -------------------------------------------------------------------------------- /oldFileBackup/BooxLocalInternational.py: -------------------------------------------------------------------------------- 1 | # -*- coding: UTF-8 -*- 2 | import sys 3 | import os 4 | from pathlib import Path 5 | 6 | # Highlights format support in 20220222 7 | # support kindle , boox local and boox cloud 8 | # Programmed by Andy 9 | # v0.2 10 | 11 | def readfile(filename): 12 | # readfile 13 | with open(filename, mode='r', encoding='UTF-8') as file: 14 | filereadlines = file.readlines() 15 | # show open file location 16 | print('Open: ' + str(filename)) 17 | # remove blank lines 18 | for i in filereadlines: 19 | if i == '\n': 20 | filereadlines.remove(i) 21 | # remove '\n' in line end 22 | for i in range(len(filereadlines)): 23 | filereadlines[i] = filereadlines[i].rstrip() 24 | return filereadlines 25 | 26 | def writefile(filename,filereadlines): 27 | # write file 28 | # file name 29 | newfile = open(filename.with_suffix('.md'), mode='w', encoding='UTF-8') 30 | # show file location 31 | print('Save: ' + str(filename.with_suffix('.md'))) 32 | newfile.writelines(filereadlines) 33 | newfile.close() 34 | 35 | def convertFromLocalStorage(filename): 36 | #readfile 37 | filereadlines = readfile(filename) 38 | outputfile = [] 39 | 40 | # show time = 1 or not = 0 41 | showTime = 0 42 | # show annotations = 1 or not = 0 43 | showAnnotations = 0 44 | # show page num = 1 or not = 0 45 | showPageNum = 0 46 | # show author = 1 or not = 0 47 | showAuthor = 1 48 | 49 | count = 0 50 | for each in filereadlines: 51 | if each.startswith('Reading Notes'): 52 | # bookname: 53 | outputfile.append('# ' + each[18:-2] + '\n\n') 54 | startIndex = each.find('<') + 2 55 | outputfile.append('Book: ' + each[startIndex:-2] + '\n') 56 | if(filereadlines[count + 1] != "null" and showAuthor): 57 | # author 58 | outputfile.append('Author: ' + filereadlines[count + 1] + '\n\n') 59 | else: 60 | outputfile.append('\n') 61 | elif each.startswith('Time:') and showTime: 62 | # time 63 | outputfile.append(each[5:] + '\n\n') 64 | elif each.startswith('【Original Text】'): 65 | # paragraph 66 | outputfile.append(each[15:] + '\n\n') 67 | elif each.startswith('【Annotations】') and showAnnotations and len(each) > 13: 68 | # annotations 69 | outputfile.append('*' + each[13:] + '*\n\n') 70 | elif each.startswith('【Page Number】') and showPageNum: 71 | # page number 72 | outputfile.append('*Page ' + each[13:] + '*\n\n') 73 | elif each.startswith("'-------------------"): 74 | outputfile.append('\n\n') 75 | count = count + 1 76 | # write file 77 | writefile(filename,outputfile) 78 | 79 | 80 | def main(filename): 81 | # read file 82 | file = open(filename, mode='r', encoding='UTF-8') 83 | firstline = file.readline() 84 | 85 | if (type(filename).__name__ == 'str'): 86 | filename = Path(filename) 87 | convertFromLocalStorage(filename) 88 | 89 | if __name__ == '__main__': 90 | if len(sys.argv) == 1: 91 | # origin file type: txt 92 | for filenames in pathlib.Path('./').rglob('*.txt'): 93 | main(filenames) 94 | elif len(sys.argv) >= 2: 95 | for i in range(1 , len(sys.argv)): 96 | main(sys.argv[i]) 97 | -------------------------------------------------------------------------------- /oldFileBackup/BooxLocalInternational_anotherVersion.py: -------------------------------------------------------------------------------- 1 | # -*- coding: UTF-8 -*- 2 | import sys 3 | import os 4 | from pathlib import Path 5 | 6 | # Highlights format support in 20220307 7 | # support kindle , boox local and boox cloud 8 | # Programmed by Andy 9 | # v0.1 10 | 11 | def readfile(filename): 12 | # readfile 13 | with open(filename, mode='r', encoding='UTF-8') as file: 14 | filereadlines = file.readlines() 15 | # show open file location 16 | print('Open: ' + str(filename)) 17 | # remove blank lines 18 | for i in filereadlines: 19 | if i == '\n': 20 | filereadlines.remove(i) 21 | # remove '\n' in line end 22 | for i in range(len(filereadlines)): 23 | filereadlines[i] = filereadlines[i].rstrip() 24 | return filereadlines 25 | 26 | def writefile(filename,filereadlines): 27 | # write file 28 | # file name 29 | newfile = open(filename.with_suffix('.md'), mode='w', encoding='UTF-8') 30 | # show file location 31 | print('Save: ' + str(filename.with_suffix('.md'))) 32 | newfile.writelines(filereadlines) 33 | newfile.close() 34 | 35 | def convertFromLocalStorage(filename): 36 | #readfile 37 | filereadlines = readfile(filename) 38 | outputfile = [] 39 | 40 | title = filereadlines[0] .split(' - ') 41 | # book name 42 | outputfile.append('# ' + title[0] + '\n\n') 43 | startIndex = title[1].rfind('(') 44 | # author 45 | outputfile.append('*' + title[1][0: startIndex - 1]+ '*\n\n') 46 | # highlight and note count 47 | outputfile.append('*' + title[1][startIndex:]+ '*\n\n') 48 | 49 | for each in filereadlines[1:]: 50 | if (each[0] == '◆'): 51 | # section 52 | outputfile.append('## ' + each[2:] + '\n\n') 53 | elif (each[0] == '▪'): 54 | # paragraph 55 | outputfile.append('> ' + each[2:] + '\n\n') 56 | # write file 57 | writefile(filename,outputfile) 58 | 59 | def main(filename): 60 | # read file 61 | file = open(filename, mode='r', encoding='UTF-8') 62 | firstline = file.readline() 63 | 64 | if (type(filename).__name__ == 'str'): 65 | filename = Path(filename) 66 | convertFromLocalStorage(filename) 67 | 68 | if __name__ == '__main__': 69 | if len(sys.argv) == 1: 70 | # origin file type: txt 71 | for filenames in pathlib.Path('./').rglob('*.txt'): 72 | main(filenames) 73 | elif len(sys.argv) >= 2: 74 | for i in range(1 , len(sys.argv)): 75 | main(sys.argv[i]) 76 | -------------------------------------------------------------------------------- /oldFileBackup/BooxLocalOS3.1.py: -------------------------------------------------------------------------------- 1 | # -*- coding: UTF-8 -*- 2 | import sys 3 | import os 4 | import pathlib 5 | import re 6 | 7 | # Highlights format support in 20210407 8 | # support kindle , boox local and boox cloud 9 | # Programmed by Andy 10 | # v0.4 11 | 12 | def readfile(filename): 13 | #readfile 14 | with open(filename, mode='r', encoding='UTF-8') as file: 15 | filereadlines = file.readlines() 16 | #remove blank lines 17 | for i in filereadlines: 18 | if i == '\n': 19 | filereadlines.remove(i) 20 | #remove '\n' in line end 21 | for i in range(len(filereadlines)): 22 | filereadlines[i] = filereadlines[i].rstrip() 23 | return filereadlines 24 | 25 | def writefile(filename,filereadlines): 26 | #write file 27 | newfile = open(filename.with_suffix('.md'), mode='w', encoding='UTF-8') 28 | newfile.writelines(filereadlines) 29 | newfile.close() 30 | 31 | def convertFromLocalStorage(filename): 32 | #readfile 33 | filereadlines = readfile(filename) 34 | #get '-------------------' line number 35 | linenum = [1] 36 | for i in range(len(filereadlines)): 37 | if '-------------------' in filereadlines[i]: 38 | linenum.append(i) 39 | #bookname,author style 40 | outputfile = [] 41 | outputfile.append('# ' + filereadlines[0][13:-2] + '\n\n') 42 | outputfile.append('**' + filereadlines[1] + '**\n\n---\n\n') 43 | #converter each highlight block to [][] 44 | newcontent = [] 45 | for i in range(len(linenum) - 1): 46 | eachcontent = [] 47 | for j in range(linenum[i] + 1, linenum[i + 1]): 48 | if filereadlines[j] != '': 49 | eachcontent.append(filereadlines[j]) 50 | newcontent.append(eachcontent) 51 | # format eachline to markdown 52 | # chapter,time,content style 53 | # Boox OS 3.1 new line for page number 54 | for i in range(len(newcontent)): 55 | start = 0 56 | if newcontent[i][0].startswith('时间:'): 57 | start = 0 58 | else: 59 | outputfile.append('**' + newcontent[i][0] + '**\n\n') 60 | start = 1 61 | outputfile.append('*' + newcontent[i][start][3:] + '*\n\n') 62 | outputfile.append('[原文]\n\n') 63 | start = start + 1 64 | for j in range(start, len(newcontent[i])): 65 | if newcontent[i][j].startswith('【原文】'): 66 | outputfile.append('> ' + newcontent[i][j][4:] + '\n\n') 67 | elif newcontent[i][j].startswith('【批注】'): 68 | outputfile.append('[批注]\n\n> ' + newcontent[i][j][4:] + '\n\n') 69 | elif newcontent[i][j].startswith('【页码】'): 70 | outputfile.append('[页码]' + newcontent[i][j][4:] + '\n\n') 71 | else: 72 | outputfile.append('> ' + newcontent[i][j] + '\n\n') 73 | outputfile.append('---\n\n') 74 | #write file 75 | writefile(filename,outputfile) 76 | 77 | 78 | def main(filename): 79 | #read file 80 | file = open(filename, mode='r', encoding='UTF-8') 81 | firstline = file.readline() 82 | 83 | if (type(filename).__name__ == 'str'): 84 | filename = Path(filename) 85 | #Judge highlights from cloud note:onenote and evernote (False) or boox local storage (True) or kindle My Clippings.txt 86 | if filename.name != 'My Clippings.txt': 87 | convertFromLocalStorage(filename) 88 | 89 | if __name__ == '__main__': 90 | if len(sys.argv) == 1: 91 | for filenames in pathlib.Path('./').rglob('*.txt'): 92 | main(filenames) 93 | elif len(sys.argv) >= 2: 94 | for i in range(1 , len(sys.argv)): 95 | main(sys.argv[i]) 96 | -------------------------------------------------------------------------------- /oldFileBackup/BooxOS2.3.py: -------------------------------------------------------------------------------- 1 | # -*- coding: UTF-8 -*- 2 | import sys 3 | import os 4 | import pathlib 5 | import re 6 | 7 | # Highlights format support in 20200313 8 | # support kindle , boox local and boox cloud 9 | # Programmed by Andy 10 | # v0.3 11 | 12 | def readfile(filename): 13 | #readfile 14 | with open(filename, mode='r', encoding='UTF-8') as file: 15 | filereadlines = file.readlines() 16 | #remove blank lines 17 | for i in filereadlines: 18 | if i == '\n': 19 | filereadlines.remove(i) 20 | #remove '\n' in line end 21 | for i in range(len(filereadlines)): 22 | filereadlines[i] = filereadlines[i].rstrip() 23 | return filereadlines 24 | 25 | def writefile(filename,filereadlines): 26 | #write file 27 | newfile = open(filename.with_suffix('.md'), mode='w', encoding='UTF-8') 28 | newfile.writelines(filereadlines) 29 | newfile.close() 30 | 31 | def converterFromLocalStorage(filename): 32 | #readfile 33 | filereadlines = readfile(filename) 34 | #get '-------------------' line number 35 | linenum = [1] 36 | for i in range(len(filereadlines)): 37 | if '-------------------' in filereadlines[i]: 38 | linenum.append(i) 39 | #bookname,author style 40 | outputfile = [] 41 | outputfile.append('# ' + filereadlines[0][13:-2] + '\n\n') 42 | outputfile.append('**' + filereadlines[1] + '**\n\n---') 43 | #converter each highlight block to [][] 44 | newcontent = [] 45 | for i in range(len(linenum) - 1): 46 | eachcontent = [] 47 | for j in range(linenum[i] + 1, linenum[i + 1]): 48 | if filereadlines[j] != '': 49 | eachcontent.append(filereadlines[j]) 50 | newcontent.append(eachcontent) 51 | #format eachline to markdown 52 | #chapter,time,content style 53 | for i in range(len(newcontent)): 54 | outputfile.append('\n\n**' + newcontent[i][0] + '**\n\n') 55 | outputfile.append('*' + newcontent[i][1][3:] + '*\n\n') 56 | outputfile.append('[原文]\n\n> ' + newcontent[i][2][4:]) 57 | for j in range(3, len(newcontent[i]) - 1): 58 | outputfile[-1] = outputfile[-1] + newcontent[i][j] + '\n\n' 59 | outputfile[-1] = outputfile[-1].rstrip() + '\n\n' 60 | outputfile.append('*[批注]' + newcontent[i][(len(newcontent[i]) - 1)][4:] + '*\n\n') 61 | outputfile.append('---') 62 | #write file 63 | writefile(filename,outputfile) 64 | 65 | def converterFromCloud(filename): 66 | #readfile 67 | filereadlines = readfile(filename) 68 | #output 69 | outputfile = [] 70 | #title 71 | outputfile.append('# ' + filereadlines[0] + '\n\n') 72 | #author 73 | outputfile.append('**' + filereadlines[1] + '**\n\n---\n\n') 74 | #check time format 75 | timereg = r'(\d{4}-\d{1,2}-\d{1,2}\s\d{1,2}:\d{1,2}:\d{1,2})' 76 | indexnum = [] 77 | #get time line number in file 78 | for i in range(0,len(filereadlines)): 79 | if re.match(timereg,filereadlines[i]): 80 | indexnum.append(i) 81 | elif filereadlines[i].startswith('BOOX读书笔记来自'): 82 | indexnum.append(i + 1) 83 | 84 | #print(indexnum) 85 | section = [] 86 | #split into sectionitem 87 | for i in range(0,len(indexnum) - 1): 88 | sectionitem = [] 89 | for j in range(indexnum[i] - 1,indexnum[i + 1] - 1): 90 | sectionitem.append(filereadlines[j]) 91 | section.append(sectionitem) 92 | for i in section: 93 | outputfile.append('**' + i[0] + '**\n\n') 94 | outputfile.append('*' + i[1] + '*\n\n') 95 | j = 2 96 | while j < len(i): 97 | outputfile.append('> ' + i[j] + '\n\n') 98 | j = j + 1 99 | outputfile.append('---\n\n') 100 | 101 | 102 | 103 | outputfile.append('*' + filereadlines[-1] + '*\n') 104 | print(outputfile) 105 | #write file 106 | writefile(filename,outputfile) 107 | 108 | def main(filename): 109 | #read file 110 | file = open(filename, mode='r', encoding='UTF-8') 111 | firstline = file.readline() 112 | 113 | if (type(filename).__name__ == 'str'): 114 | filename = Path(filename) 115 | #Judge highlights from cloud note:onenote and evernote (False) or boox local storage (True) or kindle My Clippings.txt 116 | if 'BOOX读书笔记' in firstline and filename.name != 'My Clippings.txt': 117 | converterFromLocalStorage(filename) 118 | elif filename.name != 'My Clippings.txt': 119 | converterFromCloud(filename) 120 | 121 | if __name__ == '__main__': 122 | if len(sys.argv) == 1: 123 | for filenames in pathlib.Path('./').rglob('*.txt'): 124 | main(filenames) 125 | elif len(sys.argv) >= 2: 126 | for i in range(1 , len(sys.argv)): 127 | main(sys.argv[i]) 128 | -------------------------------------------------------------------------------- /oldFileBackup/ConvertToEPUB3.2Footnote.py: -------------------------------------------------------------------------------- 1 | # -*- coding: UTF-8 -*- 2 | import sys 3 | import os 4 | import pathlib 5 | 6 | # Highlights format support in 20200313 7 | # support kindle , boox local and boox cloud 8 | # Programmed by Andy 9 | # v0.3 10 | 11 | def readfile(filename): 12 | #readfile 13 | with open(filename, mode='r', encoding='UTF-8') as file: 14 | filereadlines = file.readlines() 15 | #remove blank lines 16 | for i in filereadlines: 17 | if i == '\n': 18 | filereadlines.remove(i) 19 | #remove '\n' in line end 20 | for i in range(len(filereadlines)): 21 | filereadlines[i] = filereadlines[i].rstrip() 22 | return filereadlines 23 | 24 | def writefile(filereadlines): 25 | #write file 26 | with open('footnote1.txt', mode='w', encoding='UTF-8') as newfile: 27 | newfile.writelines(filereadlines) 28 | 29 | def converter(): 30 | #readfile 31 | filereadlines = readfile('footnote.txt') 32 | #get '-------------------' line number 33 | newlines = [] 34 | newlines.append('
\n') 35 | num = 1 36 | for i in filereadlines: 37 | if num < 10: 38 | newlines.append(' \n') 39 | else: 40 | newlines.append(' \n') 41 | #print(i[45:-4]) 42 | num = num + 1 43 | newlines.append('
\n') 44 | writefile(newlines) 45 | 46 | if __name__ == '__main__': 47 | converter() -------------------------------------------------------------------------------- /oldFileBackup/KOReaderJsonALL.py: -------------------------------------------------------------------------------- 1 | # encoding:utf-8 2 | # Highlights format support in 20210904 3 | # tested koreader android 2021.09 4 | # Programmed by Andy 5 | # v0.4 6 | 7 | from pathlib import Path 8 | import sys 9 | import os 10 | import json 11 | import time 12 | import datetime 13 | 14 | def readfile(filename): 15 | # readfile 16 | with open(filename, mode='r', encoding='UTF-8') as file: 17 | filereadlines = file.readlines() 18 | # remove blank lines 19 | for i in filereadlines: 20 | if i == '\n': 21 | filereadlines.remove(i) 22 | # remove '\n' in line end 23 | for i in range(len(filereadlines)): 24 | filereadlines[i] = filereadlines[i].rstrip() 25 | return filereadlines 26 | 27 | def writefile(filename,filereadlines): 28 | #write file 29 | newfile = open(Path(filename).stem + '.md', mode='w', encoding='UTF-8') 30 | newfile.writelines(filereadlines) 31 | newfile.close() 32 | 33 | def converterFromKOReaderJson(filename): 34 | # read json file 35 | allBooks = readfile(filename) 36 | outputfile = [] 37 | for eachBook in allBooks: 38 | jsonData = json.loads(eachBook) 39 | outputfile.append('# ' + jsonData['title'] + '\n\n---\n\n') 40 | for key in jsonData: 41 | try: 42 | outputfile.append('> ' + jsonData[key][0]['text'] + '\n\n') 43 | outputfile.append('*' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(jsonData[key][0]['time'])) + '*\n\n---\n\n') 44 | except TypeError: 45 | continue 46 | except KeyError: 47 | continue 48 | writefile(filename,outputfile) 49 | 50 | def main(inputPath): 51 | del inputPath[0] 52 | for aPath in inputPath: 53 | if Path.is_dir(Path(aPath)): 54 | for file in Path(aPath).glob('*.json'): 55 | converterFromKOReaderJson(file) 56 | if Path.is_file(Path(aPath)): 57 | if (Path(aPath).suffix == '.json'): 58 | converterFromKOReaderJson(aPath) 59 | 60 | if __name__ == '__main__': 61 | try: 62 | if len(sys.argv) >= 2: 63 | main(sys.argv) 64 | except IndexError: 65 | pass 66 | -------------------------------------------------------------------------------- /oldFileBackup/KOReaderJsonALLtoEachBook.py: -------------------------------------------------------------------------------- 1 | # encoding:utf-8 2 | # Highlights format support in 20210904 3 | # tested koreader android 2021.09 4 | # Programmed by Andy 5 | # v0.4 6 | 7 | from pathlib import Path 8 | import sys 9 | import os 10 | import json 11 | import time 12 | import datetime 13 | 14 | def readfile(filename): 15 | # readfile 16 | with open(filename, mode='r', encoding='UTF-8') as file: 17 | filereadlines = file.readlines() 18 | # remove blank lines 19 | for i in filereadlines: 20 | if i == '\n': 21 | filereadlines.remove(i) 22 | # remove '\n' in line end 23 | for i in range(len(filereadlines)): 24 | filereadlines[i] = filereadlines[i].rstrip() 25 | return filereadlines 26 | 27 | def writefile(filename,filereadlines): 28 | # write file 29 | newfile = open(filename +'.md', mode='w', encoding='UTF-8') 30 | newfile.writelines(filereadlines) 31 | newfile.close() 32 | 33 | def converterFromKOReaderJson(filename): 34 | # read json file 35 | allBooks = readfile(filename) 36 | for eachBook in allBooks: 37 | outputfile = [] 38 | jsonData = json.loads(eachBook) 39 | outputfile.append('# ' + jsonData['title'] + '\n\n---\n\n') 40 | for key in jsonData: 41 | try: 42 | outputfile.append('> ' + jsonData[key][0]['text'] + '\n\n') 43 | outputfile.append('*' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(jsonData[key][0]['time'])) + '*\n\n---\n\n') 44 | except TypeError: 45 | continue 46 | except KeyError: 47 | continue 48 | writefile(jsonData['title'],outputfile) 49 | 50 | def main(inputPath): 51 | del inputPath[0] 52 | for aPath in inputPath: 53 | if Path.is_dir(Path(aPath)): 54 | for file in Path(aPath).glob('*.json'): 55 | converterFromKOReaderJson(file) 56 | if Path.is_file(Path(aPath)): 57 | if (Path(aPath).suffix == '.json'): 58 | converterFromKOReaderJson(aPath) 59 | 60 | if __name__ == '__main__': 61 | try: 62 | if len(sys.argv) >= 2: 63 | main(sys.argv) 64 | except IndexError: 65 | pass 66 | -------------------------------------------------------------------------------- /oldFileBackup/MoonReaderProToMrexpt.py: -------------------------------------------------------------------------------- 1 | # encoding:utf-8 2 | # https://github.com/wangandi520/ClippingsToMarkdown 3 | # tested Moon Reader Pro 9.0 4 | # Programmed by Andy 5 | # v0.7 6 | # 2024.01.28 7 | 8 | from pathlib import Path 9 | import sys 10 | import time 11 | 12 | def readfile(filename): 13 | # 读取.mrexpt文件 14 | with open(filename, mode='r', encoding='UTF-8') as file: 15 | filereadlines = file.readlines() 16 | for i in range(len(filereadlines)): 17 | filereadlines[i] = filereadlines[i].rstrip() 18 | return filereadlines 19 | 20 | def writefile(filename,filereadlines): 21 | # 写入.md文件 22 | newfile = open(Path(filename).parent.joinpath(Path(filename).stem + '标注.md'), mode='w', encoding='UTF-8') 23 | newfile.writelines(filereadlines) 24 | newfile.close() 25 | print('完成:' + str(Path(filename).name)) 26 | 27 | def convertMoonReadermrexpt(filename): 28 | # 设置文章标签tags 29 | myTags = ['阅读', '标注', '读书笔记'] 30 | # 设置文章分类categories 31 | myCategories = '读书笔记' 32 | # 设置hexo文章头部信息Front-matter 33 | myFrontMatter = '---\ntitle: ' + str(Path(filename).stem) + ' 标注\ntoc: true\ntags:\n- ' + '\n- '.join(myTags) + '\ncategories: \n- ' + myCategories + '\ndate: ' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + '\n---' 34 | # 读取文件 35 | filereadlines = readfile(filename) 36 | print('处理:' + str(Path(filename).name)) 37 | # 存储所有标注 38 | allContent = [] 39 | for i in range(4, len(filereadlines), 17): 40 | eachContent = [] 41 | # filereadlines[i+4] = 第几章,从0开始 42 | # filereadlines[i+6] = 这一章内的位置 43 | eachContent.append([int(filereadlines[i+4]), int(filereadlines[i+6])]) 44 | # 划线标注 45 | eachContent.append(filereadlines[i+12]) 46 | # 手写的批注 47 | if filereadlines[i+11] != '': 48 | eachContent.append(filereadlines[i+11]) 49 | # 标注时间 50 | clippingTime = float(filereadlines[i+9])/1000 51 | clippingTimeTransfered = time.strftime("%Y.%m.%d %H:%M:%S", time.localtime(clippingTime)) 52 | eachContent.append(clippingTimeTransfered) 53 | allContent.append(eachContent) 54 | # 按照标注添加的时间顺序 = 1,还是按住标注所在书中的先后顺序 = 2,排列 55 | getOrder = 2 56 | if getOrder == 2: 57 | allContentSorted = sorted(allContent, key=lambda x: (x[0])) 58 | else: 59 | allContentSorted = allContent 60 | # 输出 61 | outputContent = [] 62 | #outputContent.append(myFrontMatter) 63 | outputContent.append('**共' + str(len(allContentSorted)) + '条标注**\n\n---') 64 | for myIndex in range(0, len(allContentSorted)): 65 | outputContent.append('\n\n> ' + allContentSorted[myIndex][1] + '\n\n') 66 | if len(allContentSorted[myIndex]) == 4: 67 | outputContent.append('**' +allContentSorted[myIndex][2] + '**\n\n') 68 | outputContent.append('*' + allContentSorted[myIndex][3] + '*\n\n') 69 | elif len(allContentSorted[myIndex]) == 3: 70 | outputContent.append('*' +allContentSorted[myIndex][2] + '*\n\n') 71 | outputContent.append('---') 72 | #if myIndex == 1: 73 | #outputContent.append('\n\n') 74 | 75 | # 写入.md文件 76 | writefile(filename, outputContent) 77 | 78 | def main(inputPath): 79 | del inputPath[0] 80 | for aPath in inputPath: 81 | if Path.is_dir(Path(aPath)): 82 | for file in Path(aPath).glob('*.mrexpt'): 83 | convertMoonReadermrexpt(file) 84 | if Path.is_file(Path(aPath)): 85 | if (Path(aPath).suffix == '.mrexpt'): 86 | convertMoonReadermrexpt(aPath) 87 | 88 | if __name__ == '__main__': 89 | try: 90 | if len(sys.argv) >= 2: 91 | main(sys.argv) 92 | except IndexError: 93 | pass -------------------------------------------------------------------------------- /oldFileBackup/MoonReaderProToMrexptForHexo.py: -------------------------------------------------------------------------------- 1 | # encoding:utf-8 2 | # https://github.com/wangandi520/ClippingsToMarkdown 3 | # Programmed by Andy 4 | # Moon Reader Pro 9.0 5 | # v0.3 6 | # 2024.02.08 7 | # 转换出的markdown文件直接可以在hexo里使用 8 | 9 | from pathlib import Path 10 | import sys 11 | import time 12 | 13 | def readfile(filename): 14 | # 读取.mrexpt文件 15 | with open(filename, mode='r', encoding='UTF-8') as file: 16 | filereadlines = file.readlines() 17 | for i in range(len(filereadlines)): 18 | filereadlines[i] = filereadlines[i].rstrip() 19 | return filereadlines 20 | 21 | def writefile(filename,filereadlines): 22 | # 写入.md文件 23 | newfile = open(Path(filename).parent.joinpath(Path(filename).stem + '标注.md'), mode='w', encoding='UTF-8') 24 | newfile.writelines(filereadlines) 25 | newfile.close() 26 | print('完成:' + str(Path(filename).name)) 27 | 28 | def convertMoonReadermrexpt(filename): 29 | # 设置文章标签tags 30 | myTags = ['阅读', '标注', '读书笔记'] 31 | # 设置文章分类categories 32 | myCategories = '读书笔记' 33 | # 设置hexo文章头部信息Front-matter,title,tags,categories,time 34 | myFrontMatter = '---\ntitle: ' + str(Path(filename).stem) + ' 标注\ntoc: true\ntags:\n- ' + '\n- '.join(myTags) + '\ncategories: \n- ' + myCategories + '\ndate: ' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + '\n---' 35 | # 读取.mrexpt文件 36 | filereadlines = readfile(filename) 37 | print('处理:' + str(Path(filename).name)) 38 | # 存储所有标注 39 | allContent = [] 40 | for i in range(4, len(filereadlines), 17): 41 | eachContent = [] 42 | # filereadlines[i+4] = 第几章,从0开始,chapter 43 | # filereadlines[i+6] = 这一章内的位置,location in chapter 44 | eachContent.append([int(filereadlines[i+4]), int(filereadlines[i+6])]) 45 | # 划线标注,underline clipping 46 | eachContent.append(filereadlines[i+12]) 47 | # 手写的批注,input clipping 48 | if filereadlines[i+11] != '': 49 | eachContent.append(filereadlines[i+11]) 50 | # 标注时间,time 51 | clippingTime = float(filereadlines[i+9])/1000 52 | clippingTimeTransfered = time.strftime("%Y.%m.%d %H:%M:%S", time.localtime(clippingTime)) 53 | eachContent.append(clippingTimeTransfered) 54 | allContent.append(eachContent) 55 | # 按照标注添加的时间顺序 = 1,order by time,还是按住标注所在书中的先后顺序 = 2,order by location,排列 56 | getOrder = 2 57 | if getOrder == 2: 58 | allContentSorted = sorted(allContent, key=lambda x: (x[0])) 59 | else: 60 | allContentSorted = allContent 61 | # 输出 62 | outputContent = [] 63 | outputContent.append(myFrontMatter) 64 | outputContent.append('\n\n**共' + str(len(allContentSorted)) + '条标注**\n\n---') 65 | for myIndex in range(0, len(allContentSorted)): 66 | outputContent.append('\n\n> ' + allContentSorted[myIndex][1] + '\n\n') 67 | if len(allContentSorted[myIndex]) == 4: 68 | outputContent.append('**' +allContentSorted[myIndex][2] + '**\n\n') 69 | outputContent.append('*' + allContentSorted[myIndex][3] + '*\n\n') 70 | elif len(allContentSorted[myIndex]) == 3: 71 | outputContent.append('*' +allContentSorted[myIndex][2] + '*\n\n') 72 | outputContent.append('---') 73 | # 在主页显示几条标注,显示2条myIndex == 1 74 | if myIndex == 1: 75 | outputContent.append('\n\n') 76 | # 写入.md文件 77 | writefile(filename, outputContent) 78 | 79 | def main(inputPath): 80 | del inputPath[0] 81 | for aPath in inputPath: 82 | if Path.is_dir(Path(aPath)): 83 | for eachFile in Path(aPath).glob('**/*'): 84 | if (Path(eachFile).suffix.lower() == '.mrexpt'): 85 | convertMoonReadermrexpt(eachFile) 86 | if Path.is_file(Path(aPath)): 87 | if (Path(aPath).suffix.lower() == '.mrexpt'): 88 | convertMoonReadermrexpt(aPath) 89 | 90 | if __name__ == '__main__': 91 | try: 92 | if len(sys.argv) >= 2: 93 | main(sys.argv) 94 | except IndexError: 95 | pass -------------------------------------------------------------------------------- /oldFileBackup/MoonReaderProToTXT.py: -------------------------------------------------------------------------------- 1 | # encoding:utf-8 2 | # Highlights format support in 20210928 3 | # tested Moon Reader Pro 6.9 4 | # Programmed by Andy 5 | # v0.4 6 | 7 | from pathlib import Path 8 | import sys 9 | import time 10 | 11 | def readfile(filename): 12 | # readfile 13 | with open(filename, mode='r', encoding='UTF-8') as file: 14 | filereadlines = file.readlines() 15 | return filereadlines 16 | 17 | def writefile(filename,filereadlines): 18 | # write file 19 | newfile = open(Path(filename).stem + '.md', mode='w', encoding='UTF-8') 20 | newfile.writelines(filereadlines) 21 | newfile.close() 22 | 23 | def convertMoonReaderTXT(filename): 24 | # readfile 25 | filereadlines = readfile(filename) 26 | # bookname,author style 27 | eachcontent = [] 28 | bookName = filereadlines[0].split(' - ')[0] 29 | findLoc = filereadlines[0].split(' - ')[1].find('(') 30 | authorName = filereadlines[0].split(' - ')[1][0:findLoc - 1] 31 | otherMsg = filereadlines[0].split(' - ')[1][findLoc:].replace('\n','') 32 | eachcontent.append('---\n\n# ' + bookName + '\n\n') 33 | eachcontent.append('**' + authorName + '**\n\n') 34 | eachcontent.append('**' + otherMsg + '**\n\n') 35 | for i in filereadlines: 36 | if (i[0] == '◆'): 37 | eachcontent.append('---\n\n## ' + i[2:] + '\n') 38 | # time 39 | if (i[0] == '▪'): 40 | eachcontent.append('> ' + i[2:] + '\n') 41 | 42 | eachcontent.append('---') 43 | # write file 44 | writefile(filename,eachcontent) 45 | 46 | def main(inputPath): 47 | del inputPath[0] 48 | for aPath in inputPath: 49 | if Path.is_dir(Path(aPath)): 50 | for file in Path(aPath).glob('*.txt'): 51 | convertMoonReaderTXT(file) 52 | if Path.is_file(Path(aPath)): 53 | if (Path(aPath).suffix == '.txt'): 54 | convertMoonReaderTXT(aPath) 55 | 56 | if __name__ == '__main__': 57 | try: 58 | if len(sys.argv) >= 2: 59 | main(sys.argv) 60 | except IndexError: 61 | pass -------------------------------------------------------------------------------- /oldFileBackup/MoonReaderProToTXTbyQQ.py: -------------------------------------------------------------------------------- 1 | # encoding:utf-8 2 | # Highlights format support in 20210928 3 | # tested Moon Reader Pro 6.9 4 | # Programmed by Andy 5 | # v0.4 6 | 7 | from pathlib import Path 8 | import sys 9 | import time 10 | 11 | def readfile(filename): 12 | # readfile 13 | with open(filename, mode='r', encoding='UTF-8') as file: 14 | filereadlines = file.readlines() 15 | return filereadlines 16 | 17 | def writefile(filename,filereadlines): 18 | # write file 19 | newfile = open(Path(filename).stem + '.md', mode='w', encoding='UTF-8') 20 | newfile.writelines(filereadlines) 21 | newfile.close() 22 | 23 | def convertMoonReaderTXT(filename): 24 | # readfile 25 | filereadlines = readfile(filename) 26 | # bookname,author style 27 | eachcontent = [] 28 | bookName = filereadlines[0].split(' - ')[0] 29 | findLoc = filereadlines[0].split(' - ')[1].find('(') 30 | authorName = filereadlines[0].split(' - ')[1][0:findLoc - 1] 31 | otherMsg = filereadlines[0].split(' - ')[1][findLoc:].replace('\n','') 32 | eachcontent.append('---\n\n# ' + bookName + '\n\n') 33 | eachcontent.append('**' + authorName + '**\n\n') 34 | eachcontent.append('**' + otherMsg + '**\n\n') 35 | for i in filereadlines[3:]: 36 | if (i[0] == '◆'): 37 | eachcontent.append('---\n\n## ' + i[2:] + '\n') 38 | # time 39 | elif (i[0] != '\n'): 40 | if (i[0] != ' '): 41 | eachcontent.append('> ' + i + '\n') 42 | else: 43 | eachcontent.append('> ' + i[1:] + '\n') 44 | 45 | eachcontent.append('---') 46 | # write file 47 | writefile(filename,eachcontent) 48 | 49 | def main(inputPath): 50 | del inputPath[0] 51 | for aPath in inputPath: 52 | if Path.is_dir(Path(aPath)): 53 | for file in Path(aPath).glob('*.txt'): 54 | convertMoonReaderTXT(file) 55 | if Path.is_file(Path(aPath)): 56 | if (Path(aPath).suffix == '.txt'): 57 | convertMoonReaderTXT(aPath) 58 | 59 | if __name__ == '__main__': 60 | try: 61 | if len(sys.argv) >= 2: 62 | main(sys.argv) 63 | except IndexError: 64 | pass -------------------------------------------------------------------------------- /文石BOOXOS4.0标注(.txt)转markdown或hexo(.md).py: -------------------------------------------------------------------------------- 1 | # encoding:utf-8 2 | # https://github.com/wangandi520/ClippingsToMarkdown 3 | # Programmed by Andy 4 | # BOOX OS 4.0 5 | # v0.1 6 | # 2025.03.17 7 | # 转换出的markdown文件直接可以在hexo里使用,一般放在hexo\source\_posts文件夹里 8 | 9 | from pathlib import Path 10 | import sys 11 | import time 12 | import re 13 | 14 | # 把可以更改的设置都放在这里 15 | CONFIG = { 16 | 'toHexoMode': True, # True: 转换成hexo博客的格式,False: 转换成一般markdown格式 17 | 'tags': ['阅读', '标注', '读书笔记'], # hexo博客的标签 18 | 'categories': '读书笔记', # hexo博客的分类 19 | 'preview_notes': 2, # 主页显示的标注数量 20 | 'sort_by_location': True # True: 按标注在书中的先后顺序,False: 按标注添加的时间顺序 21 | } 22 | 23 | def validFileName(oldFileName): 24 | # '/ \ : * ? " < > |' 25 | # 替换为下划线 26 | validChars = r"[\/\\\:\*\?\"\<\>\|]" 27 | newFileName = re.sub(validChars, "", oldFileName) 28 | return newFileName 29 | 30 | def readfile(filename: Path) -> list[str]: 31 | with open(filename, mode='r', encoding='UTF-8') as file: 32 | return [line.rstrip() for line in file] 33 | 34 | def writefile(filename: Path, filereadlines: list[str]) -> None: 35 | # 写入.md文件 36 | newfile = open(Path(filename).parent.joinpath(Path(filename).stem + '标注.md'), mode='w', encoding='UTF-8') 37 | newfile.writelines(filereadlines) 38 | newfile.close() 39 | print('完成:' + str(Path(filename).name)) 40 | 41 | def getEachClippings(filename: Path) -> list[str]: 42 | groups = [] 43 | 44 | try: 45 | with open(filename, 'r', encoding='utf-8') as file: 46 | lines = file.readlines() 47 | 48 | if not lines: 49 | return groups 50 | 51 | # 第一行作为第一组 52 | groups.append([lines[0].strip()]) 53 | 54 | if len(lines) < 2: 55 | return groups 56 | 57 | # 第二行到第一个分隔符作为第二组 58 | current_group = [] 59 | i = 1 # 从第二行开始 60 | 61 | # 处理第二组(第二行到第一个分隔符) 62 | while i < len(lines) and lines[i].strip() != "-------------------": 63 | current_group.append(lines[i].strip()) 64 | i += 1 65 | 66 | if current_group: 67 | groups.append(current_group) 68 | 69 | # 跳过第一个分隔符 70 | if i < len(lines): 71 | i += 1 72 | 73 | # 处理剩余的组(每两个分隔符之间) 74 | current_group = [] 75 | in_group = True 76 | 77 | while i < len(lines): 78 | line = lines[i].strip() 79 | 80 | if line == "-------------------": 81 | if in_group: 82 | # 当遇到分隔符且在组内时,结束当前组 83 | if current_group: 84 | groups.append(current_group) 85 | current_group = [] 86 | in_group = False 87 | else: 88 | # 当遇到分隔符且不在组内时,开始新的一组 89 | in_group = True 90 | elif in_group: 91 | current_group.append(line) 92 | 93 | i += 1 94 | 95 | # 处理文件末尾可能的未完成组 96 | if in_group and current_group: 97 | groups.append(current_group) 98 | 99 | except FileNotFoundError: 100 | print("错误:1.txt 文件不存在") 101 | except Exception as e: 102 | print(f"读取文件时发生错误: {e}") 103 | 104 | return groups 105 | 106 | def convertBooxTxt(filename: Path) -> None: 107 | # 读取.mrexpt文件 108 | # filereadlines = readfile(filename) 109 | print('处理:' + str(Path(filename).name)) 110 | # 存储所有标注 111 | getAllClippings = [] 112 | getAllClippings = getEachClippings(filename) 113 | # # 按照标注添加的时间顺序 = 1,order by time,还是按住标注所在书中的先后顺序 = 2,order by location,排列 114 | # if CONFIG['sort_by_location']: 115 | # allContentSorted = sorted(allContent, key=lambda x: (x[0])) 116 | # else: 117 | # allContentSorted = allContent 118 | # # 输出 119 | outputContent = [] 120 | # hexo文章头部信息Front-matter,title,tags,categories,time 121 | if CONFIG['toHexoMode']: 122 | myFrontMatter = '---\ntitle: ' + getAllClippings[0][0][7:] + ' 标注\ntoc: true\ntags:\n- ' + '\n- '.join(CONFIG['tags']) + '\ncategories: \n- ' + CONFIG['categories'] + '\ndate: ' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + '\n---\n\n' 123 | else: 124 | myFrontMatter = '## ' + getAllClippings[0][0][7:] + '\n\n' 125 | outputContent.append(myFrontMatter) 126 | outputContent.append('**共' + str(len(getAllClippings) - 1) + '条标注**\n\n---\n\n') 127 | for eachClippings in getAllClippings[1:]: 128 | startIndex = 0 129 | if '页码' not in eachClippings[0]: 130 | outputContent.append('## ' + eachClippings[0] + '\n\n') 131 | startIndex = 1 132 | for tempEach in range(startIndex, len(eachClippings)): 133 | if '页码' in eachClippings[tempEach]: 134 | outputContent.append('*' + eachClippings[tempEach] + '*\n\n') 135 | else: 136 | outputContent.append('> ' + eachClippings[tempEach] + '\n\n') 137 | 138 | outputContent.append('---\n\n') 139 | # # 写入.md文件 140 | writefile(validFileName(getAllClippings[0][0][7:]), outputContent) 141 | 142 | def main(inputPath: list[str]) -> None: 143 | fileType = {'.txt'} 144 | for eachPath in inputPath[1:]: 145 | eachPath = Path(eachPath) 146 | if Path.is_dir(eachPath): 147 | for eachFile in eachPath.glob('**/*'): 148 | if eachFile.suffix in fileType: 149 | convertBooxTxt(eachFile) 150 | if Path.is_file(eachPath): 151 | print(eachPath) 152 | if eachPath.suffix in fileType: 153 | convertBooxTxt(eachPath) 154 | 155 | if __name__ == '__main__': 156 | try: 157 | if len(sys.argv) >= 2: 158 | main(sys.argv) 159 | else: 160 | print('请拖拽文件到本脚本,或者命令行运行时添加文件路径') 161 | except Exception as e: 162 | print(f"程序运行出错: {str(e)}") -------------------------------------------------------------------------------- /静读天下专业版标注(.mrexpt)转markdown或hexo(.md).py: -------------------------------------------------------------------------------- 1 | # encoding:utf-8 2 | # https://github.com/wangandi520/ClippingsToMarkdown 3 | # Programmed by Andy 4 | # Moon Reader Pro 9.0 5 | # v0.5 6 | # 2025.03.07 7 | # 转换出的markdown文件直接可以在hexo里使用,一般放在hexo\source\_posts文件夹里 8 | 9 | from pathlib import Path 10 | import sys 11 | import time 12 | import re 13 | 14 | # 把可以更改的设置都放在这里 15 | CONFIG = { 16 | 'toHexoMode': True, # True: 转换成hexo博客的格式,False: 转换成一般markdown格式 17 | 'tags': ['阅读', '标注', '读书笔记'], # hexo博客的标签 18 | 'categories': '读书笔记', # hexo博客的分类 19 | 'preview_notes': 2, # 主页显示的标注数量 20 | 'sort_by_location': True # True: 按标注在书中的先后顺序,False: 按标注添加的时间顺序 21 | } 22 | 23 | def validFileName(oldFileName): 24 | # '/ \ : * ? " < > |' 25 | # 替换为下划线 26 | validChars = r"[\/\\\:\*\?\"\<\>\|]" 27 | newFileName = re.sub(validChars, "", oldFileName) 28 | return newFileName 29 | 30 | def readfile(filename: Path) -> list[str]: 31 | with open(filename, mode='r', encoding='UTF-8') as file: 32 | return [line.rstrip() for line in file] 33 | 34 | def writefile(filename: Path, filereadlines: list[str]) -> None: 35 | # 写入.md文件 36 | newfile = open(Path(filename).parent.joinpath(Path(filename).stem + '标注.md'), mode='w', encoding='UTF-8') 37 | newfile.writelines(filereadlines) 38 | newfile.close() 39 | print('完成:' + str(Path(filename).name)) 40 | 41 | def convertMoonReadermrexpt(filename: Path) -> None: 42 | # 读取.mrexpt文件 43 | filereadlines = readfile(filename) 44 | print('处理:' + str(Path(filename).name)) 45 | # 存储所有标注 46 | allContent = [] 47 | for i in range(4, len(filereadlines), 17): 48 | eachContent = [] 49 | # filereadlines[i+4] = 第几章,从0开始,chapter 50 | # filereadlines[i+6] = 这一章内的位置,location in chapter 51 | eachContent.append([int(filereadlines[i+4]), int(filereadlines[i+6])]) 52 | # 划线标注,underline clipping 53 | eachContent.append(filereadlines[i+12]) 54 | # 手写的批注,input clipping 55 | if filereadlines[i+11] != '': 56 | eachContent.append(filereadlines[i+11]) 57 | # 标注时间,time 58 | clippingTime = float(filereadlines[i+9])/1000 59 | clippingTimeTransfered = time.strftime("%Y.%m.%d %H:%M:%S", time.localtime(clippingTime)) 60 | eachContent.append(clippingTimeTransfered) 61 | allContent.append(eachContent) 62 | # 按照标注添加的时间顺序 = 1,order by time,还是按住标注所在书中的先后顺序 = 2,order by location,排列 63 | if CONFIG['sort_by_location']: 64 | allContentSorted = sorted(allContent, key=lambda x: (x[0])) 65 | else: 66 | allContentSorted = allContent 67 | # 输出 68 | outputContent = [] 69 | # hexo文章头部信息Front-matter,title,tags,categories,time 70 | if CONFIG['toHexoMode']: 71 | myFrontMatter = '---\ntitle: ' + str(Path(filename).stem) + ' 标注\ntoc: true\ntags:\n- ' + '\n- '.join(CONFIG['tags']) + '\ncategories: \n- ' + CONFIG['categories'] + '\ndate: ' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + '\n---\n\n' 72 | else: 73 | myFrontMatter = '## ' + str(Path(filename).stem) + '\n\n' 74 | outputContent.append(myFrontMatter) 75 | outputContent.append('**共' + str(len(allContentSorted)) + '条标注**\n\n---') 76 | for myIndex in range(0, len(allContentSorted)): 77 | outputContent.append('\n\n> ' + allContentSorted[myIndex][1] + '\n\n') 78 | if len(allContentSorted[myIndex]) == 4: 79 | outputContent.append('**' +allContentSorted[myIndex][2] + '**\n\n') 80 | outputContent.append('*' + allContentSorted[myIndex][3] + '*\n\n') 81 | elif len(allContentSorted[myIndex]) == 3: 82 | outputContent.append('*' +allContentSorted[myIndex][2] + '*\n\n') 83 | outputContent.append('---') 84 | # 在主页显示几条标注,显示2条myIndex == 1 85 | if myIndex == CONFIG['preview_notes'] - 1 and CONFIG['toHexoMode']: 86 | outputContent.append('\n\n') 87 | # 写入.md文件 88 | writefile(validFileName(filename.name), outputContent) 89 | 90 | def main(inputPath: list[str]) -> None: 91 | fileType = {'.mrexpt'} 92 | for eachPath in inputPath[1:]: 93 | eachPath = Path(eachPath) 94 | if Path.is_dir(eachPath): 95 | for eachFile in eachPath.glob('**/*'): 96 | if eachFile.suffix in fileType: 97 | convertMoonReadermrexpt(eachFile) 98 | if Path.is_file(eachPath): 99 | if eachPath.suffix in fileType: 100 | convertMoonReadermrexpt(eachPath) 101 | 102 | if __name__ == '__main__': 103 | try: 104 | if len(sys.argv) >= 2: 105 | main(sys.argv) 106 | else: 107 | print('请拖拽文件到本脚本,或者命令行运行时添加文件路径') 108 | except Exception as e: 109 | print(f"程序运行出错: {str(e)}") --------------------------------------------------------------------------------