静读天下mrexpt转md

第一版

1.在平板或手机上标注的笔记导出上传到电脑
2.git clone https://gitclone.com/github.com/wangandi520/ClippingsToMarkdown.git
3.把 *.mrexpt 文件放到该项目下
4.执行命令 python .\MoonReaderProToMrexpt.py car.mrexpt
5.在该目录下即可看到转换的md文件

参考:
1)https://andi.wang/2021/03/15/文石Boox,Kindle,静读天下专业版,微信读书,KOReader的标注转换为Markdown格式/
2)https://github.com/wangandi520/ClippingsToMarkdown

image

第二版

由于转换出来的样式不太符合我个人的偏好,所以对代码进行了调整,同时也不需要在控制台输入文件名(在python代码里输入即可)。主要是对输出内容和传参做了改动:
image

# encoding:utf-8
# https://github.com/wangandi520/ClippingsToMarkdown
# tested Moon Reader Pro 9.0
# Programmed by Andy
# v0.7
# 2024.01.28

from pathlib import Path
import sys
import time

def readfile(filename):
    # 读取.mrexpt文件
    with open(filename, mode='r', encoding='UTF-8') as file:
        filereadlines = file.readlines()
    for i in range(len(filereadlines)):
        filereadlines[i] = filereadlines[i].rstrip()
    return filereadlines

def writefile(filename,filereadlines):
    # 写入.md文件
    newfile = open(Path(filename).parent.joinpath(Path(filename).stem + '标注.md'), mode='w', encoding='UTF-8')
    newfile.writelines(filereadlines)
    newfile.close()
    print('完成:' + str(Path(filename).name))
    
def convertMoonReadermrexpt(filename):
    # 设置文章标签tags
    myTags = ['阅读', '标注', '读书笔记']
    # 设置文章分类categories
    myCategories = '读书笔记'
    # 设置hexo文章头部信息Front-matter
    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---'
    # 读取文件
    filereadlines = readfile(filename)
    print('处理:' + str(Path(filename).name))
    # 存储所有标注
    allContent = []
    for i in range(4, len(filereadlines), 17):
        eachContent = []
        # filereadlines[i+4] = 第几章,从0开始
        # filereadlines[i+6] = 这一章内的位置
        eachContent.append([int(filereadlines[i+4]), int(filereadlines[i+6])])
        # 划线标注
        eachContent.append(filereadlines[i+12])
        # 手写的批注
        if filereadlines[i+11] != '':
            eachContent.append(filereadlines[i+11])
        # 标注时间
        clippingTime = float(filereadlines[i+9])/1000
        clippingTimeTransfered = time.strftime("%Y.%m.%d %H:%M:%S", time.localtime(clippingTime))
        eachContent.append(clippingTimeTransfered)
        allContent.append(eachContent)
    # 按照标注添加的时间顺序 = 1,还是按住标注所在书中的先后顺序 = 2,排列
    getOrder = 2
    if getOrder == 2:
        allContentSorted = sorted(allContent, key=lambda x: (x[0]))
    else:
        allContentSorted = allContent
    # 输出
    outputContent = []
    #outputContent.append(myFrontMatter)
    for myIndex in range(0, len(allContentSorted)):
        outputContent.append('- ' + allContentSorted[myIndex][1] + '\n\n')
    # 写入.md文件
    writefile(filename, outputContent)
    
def main():
   # 放入需要转换的文件名
   convertMoonReadermrexpt('car.mrexpt')
        
if __name__ == '__main__':
    try:
        main()
    except IndexError:
        pass

效果图如下:
image

使用 vscode 替换角标:[\d+]

posted @ 2024-12-22 09:23  LHX2018  阅读(302)  评论(0)    收藏  举报