File: import_qq_userdict.py

package info (click to toggle)
sunpinyin 2.0.3%2Bgit20120607-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 1,372 kB
  • sloc: cpp: 14,549; python: 1,309; makefile: 154
file content (31 lines) | stat: -rwxr-xr-x 710 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/python

import os, sys
import codecs
from importer import import_to_sunpinyin_user_dict

def load_qq_user_dict (fname):
    result = []
    f = codecs.open (fname, "r", "UTF-16")
    for l in f:
        if l[0] in ('\n', '\r'):
            continue

        try:
            pystr, utf8str, _ = l.strip().split(",")[0].split(" ")
            result.append ((pystr[1:], utf8str))
        except:
            pass

    return result

def main ():
    if len (sys.argv) != 2:
        print "Please specify the QQ PinYin exported user dict file!"
        exit (1)

    qq_user_dict = load_qq_user_dict(sys.argv[1])
    import_to_sunpinyin_user_dict (qq_user_dict)

if __name__ == "__main__":
    main()