Last active
June 14, 2018 09:34
-
-
Save k141303/9c686c33944f69b475decd0a5285126f to your computer and use it in GitHub Desktop.
ejdicをMDict形式に変換します。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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