Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kindle标注导出为CSV或者其他Anki可以接受的格式 #8

Open
lzcapp opened this issue Nov 25, 2024 · 10 comments
Open

Kindle标注导出为CSV或者其他Anki可以接受的格式 #8

lzcapp opened this issue Nov 25, 2024 · 10 comments
Assignees
Labels
enhancement New feature or request

Comments

@lzcapp
Copy link
Owner

lzcapp commented Nov 25, 2024

@Steven630#6 提出:

Kindle标注能导出成CSV或者其他anki可以接受的格式吗?

@lzcapp lzcapp added the enhancement New feature or request label Nov 25, 2024
@lzcapp lzcapp self-assigned this Nov 25, 2024
@Steven630
Copy link

Steven630 commented Nov 25, 2024

谢谢大佬,原帖已经回复#6 (comment)

在这里补充一下,根据anki的说明,CSV文件最开始几行可以加上header,这样Anki在导入的时候能直接根据header设置相应格式和选项

方式是
#key:value

比如
#separator:Comma
#html:true
#columns:Front,Back
#notetype:Test
#deck:Chinese

这表示文件的列是用逗号分隔的(这个可以和导出时的分隔符一致,还可以是Tab、Semicolon等等),html格式启用,notetype是Test,牌组是Chinese。

所有header支持的key和value在这里:
https://docs.ankiweb.net/importing/text-files.html#file-headers

要是可以让用户在导出前设定header就更好了,这样Anki导入的时候直接都设置好了。

@lzcapp
Copy link
Owner Author

lzcapp commented Nov 25, 2024

image

@lzcapp
Copy link
Owner Author

lzcapp commented Nov 25, 2024

@Steven630 也就是说先不管headers,我至少需要做到导出一个csv文件,这样在Anki中就能一一对应和导入了?

@Steven630
Copy link

是的,有了CSV就可以。CSV建议所有的元素都单独成列,用户在Anki导入的时候选择哪些需要、对应到哪个field就可以了。

单词也是一样的(单词、原形、上下文、书籍、作者、语言、时间等等信息都各为一列)。以前的Kindle Mate生词本应该是有导出为CSV功能的,标注没试过。

@Steven630
Copy link

Steven630 commented Nov 25, 2024

image

截图左边是用户Anki卡片自带的fields,右边可选的就是CSV每列的表头,标注导出功能实现后。Anki导入界面右边这栏就可以自主选择“标记内容”、“书名”、“位置”等等,也可以选择nothing跳过。

目前需要的第一步只是把那些信息都变成一个大CSV。

@Steven630
Copy link

Steven630 commented Nov 25, 2024

Screenshot_20241125_120037.jpg

Screenshot_20241125_120136.jpg

第一张截图是用Python把生词本转换为CSV格式的做法,第二张就是Anki导入相应CSV的界面。

    with open(export_path, 'w', newline='', encoding='utf-8') as csvfile:
        # Write Anki import settings as headers
        csvfile.write("#separator:Comma\n")
        csvfile.write("#html:true\n")
        csvfile.write("#tags:\n")
        csvfile.write("#columns:Front,Back,AI\n")
        csvfile.write(f"#notetype:{notetype}\n")
        csvfile.write(f"#deck:{deck}\n")
        csvfile.write("#notetype column:\n")
        csvfile.write("#deck column:\n")
        csvfile.write("#tags column:\n")
        csvfile.write("#guid column:\n")
        csvfile.write("#existing notes:duplicate\n")
        csvfile.write("#match scope:notetype and deck\n")

        # Write data rows
        writer = csv.writer(csvfile)
        for word in words:
            # Map fields to values
            front = word[3]  # 'stem'
            back = word[1]  # 'usage'
            ai = word[6]

            # Write row
            writer.writerow([front, back, ai, notetype, deck])

@Steven630
Copy link

根据上面的代码,似乎是要加一行表示各列内容的header才行,否则Anki不一定能识别

csvfile.write("#columns:Front,Back,AI\n")

@Steven630
Copy link

大佬,这个功能大概什么时候有望实现呀😊@lzcapp

@lzcapp
Copy link
Owner Author

lzcapp commented Dec 16, 2024

@Steven630 说实话最近有点忙🤣,我打算是先把那个导入的问题解决了,然后再实现这些feature。

@Steven630
Copy link

好的好的,辛苦啦

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants