Skip to content

Instantly share code, notes, and snippets.

@private-yusuke
Created May 13, 2018 06:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save private-yusuke/23f64c539b7b9f0524e331311064a6b1 to your computer and use it in GitHub Desktop.
Save private-yusuke/23f64c539b7b9f0524e331311064a6b1 to your computer and use it in GitHub Desktop.
ことえりの辞書をGoogle日本語入力用に変換するPythonスクリプト
from xml.etree import ElementTree
from sys import argv, exit
import os.path
if len(argv) <= 2:
print("Too few arguments: <command> <path> <output>")
print("BE CAREFUL NOT TO OVERWRITE YOUR IMPORTANT DATA.")
print("This script writes the output even if there's already a file named <output>.")
exit(1)
if os.path.exists(argv[2]):
print("Are you sure you want to overwrite the file", argv[2], "? (Y/N)")
ans = input()
if not(ans is "Y" or ans is "Yes" or ans is "yes" or ans is "y"):
exit(0)
tree = ElementTree.parse(argv[1])
root = tree.getroot()
dict = {}
for e in list(root[0]):
dict[e[3].text] = e[1].text
f = open(argv[2], "w")
for key, value in dict.items():
f.write("{} {} 名詞\n".format(key, value))
f.close()
# ① システム環境設定を起動する
# ② キーボード -> ユーザ辞書 を開く
# ③ 左に登録されているリストの要素をすべて選択し、適当な場所にD&Dする。このとき「ユーザ辞書.plist」が作られる。
# ④ 実行する (例: python kotoeri_to_google.py ユーザ辞書.plist ~/Desktop/ユーザ辞書.txt)
# ⑤ 第二引数の場所にGoogle日本語入力の辞書のインポート用ファイルが生成されるので、辞書ツール.appからインポートする
# ⑥ しあわせ
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment