Skip to content

Instantly share code, notes, and snippets.

@k141303 k141303/ejdic_to_mdict.py
Last active Jun 14, 2018

Embed
What would you like to do?
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
You can’t perform that action at this time.