Last active
December 24, 2021 10:57
-
-
Save YumNumm/a1a585e82d685754ff8dfc374a067a98 to your computer and use it in GitHub Desktop.
iOSのユーザ辞書ファイル(/var/mobile/Library/KeyboardServices/TextReplacements.db)を解析し、Android(GBoard)にインポート可能なzipファイルを作成する
This file contains 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
#!/usr/bin/python3 | |
# -*- coding: utf-8 -*- | |
""" | |
* 説明 : iOSのユーザ辞書ファイル(/var/mobile//Library/.../TextReplacements.db)を解析し、Android(GBoard)にインポート可能なzipファイルを作成する | |
* 作成日 : 2021/08/14 | |
* 作成者 : @YumNumm | |
* LICNSE : MIT | |
""" | |
from encodings import utf_8 | |
import sqlite3 | |
import zipfile | |
def main(): | |
dbname = "TextReplacements.db" | |
conn = sqlite3.connect(dbname) | |
cur = conn.cursor() | |
cur.execute("SELECT ZPHRASE,ZSHORTCUT FROM ZTEXTREPLACEMENTENTRY ") | |
res = cur.fetchall() | |
print("txtファイルに出力中...") # dictionary.txtに出力 | |
with open("./dictionary.txt", encoding="utf_8", mode="w") as f: | |
for r in res: | |
f.write(r[1] + "\t" + r[0] + "\n") | |
print("zipファイルを作成中...") # dictionary.zipに出力 | |
with zipfile.ZipFile( | |
"./dictionary.zip", "w", compression=zipfile.ZIP_DEFLATED | |
) as zf: | |
zf.write("./dictionary.txt") | |
print("終了") | |
cur.close() | |
conn.close() | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment