Skip to content

Instantly share code, notes, and snippets.

@chouch0u
Created March 16, 2016 17:01
Show Gist options
  • Save chouch0u/51ef8e9944257a437aeb to your computer and use it in GitHub Desktop.
Save chouch0u/51ef8e9944257a437aeb to your computer and use it in GitHub Desktop.
将 Eudic 网页版本导出的生词本单词转换为 Anki 可用的格式。
import sys
import re
import os
if os.path.isfile(sys.argv[2]):
os.remove(sys.argv[2])
eudic = open(sys.argv[1])
anki = open(sys.argv[2], 'a')
lines = []
for i in eudic:
lines.append(i.decode('utf-8'))
world = []
for i in lines:
world.append(i.split("\t"))
txt = ""
for i in world:
meaning = ""
for n in range(2, len(i)):
meaning = meaning + i[n]
meaning = re.sub(",", ";", meaning)
txt = i[1] + "," + meaning
anki.write(txt.encode('utf-8'))
anki.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment