Skip to content

Instantly share code, notes, and snippets.

@k141303
Last active June 14, 2018 09:34
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save k141303/9c686c33944f69b475decd0a5285126f to your computer and use it in GitHub Desktop.
ejdicをMDict形式に変換します。
# -*- coding: utf-8 -*-
"""
ejdicをMDict形式に変換します。
"""
from writemdict import MDictWriter, encrypt_key
import sys
args = sys.argv
d = {}
idiom = {}
with open(args[1]) as f:
line = f.readline()
while line:
word,meaning = line.split('\t',1)
word = word.rstrip()
meaning = meaning.replace('/','\n').replace('・',',')
line = f.readline()
words = word.split(',')
for word in words:
word = word.strip()
if " " in word or "-" in word:
idiom[word] = meaning
else:
d[word] = meaning
with open("ejdic.mdx", "wb") as outfile:
writer = MDictWriter(d,
"EJDIC",
"\"UTF-8\" encoding.",
encoding="utf-8")
writer.write(outfile)
with open("ejdiciom.mdx", "wb") as outfile:
writer = MDictWriter(idiom,
"EJDICiom",
"\"UTF-8\" encoding.",
encoding="utf-8")
writer.write(outfile)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment