-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmdbgRedisInserter.py
executable file
·35 lines (28 loc) · 1.06 KB
/
mdbgRedisInserter.py
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
32
33
34
35
#!/usr/bin/env python3
import mdbgCedict
import redisImporter
import redisChineseEnglishDict
class RedisImporterCedict(redisChineseEnglishDict.RedisChineseEnglishDict):
def db_set(self, key, value):
redisImporter.set(key, value)
def db_sadd(self, *args):
redisImporter.sadd(*args)
def db_zadd(self, *args):
redisImporter.zadd(*args)
def importMdbgFile(filename):
mdbgdict = mdbgCedict.MdbgCedict(filename)
redisdict = RedisImporterCedict(host='not_used')
for line in mdbgdict.get_all_entries():
entry = mdbgCedict.MdbgDictEntry.parse_entry_line(line)
for definition in entry.englishdefinitions:
redisdict.add_definition(simplified=entry.simplified,
pinyin=entry.pinyin,
pos=entry.partofspeech,
definition=definition)
if __name__ == '__main__':
import sys
try:
importMdbgFile(sys.argv[1])
except (BrokenPipeError, IOError):
pass
sys.stderr.close()