MCPcopy
hub / github.com/skywind3000/ECDICT / export_mdict

Method export_mdict

stardict.py:1374–1397  ·  view source on GitHub ↗
(self, wordmap, outname)

Source from the content-addressed store, hash-verified

1372
1373 # 导出 mdict 的源文件
1374 def export_mdict (self, wordmap, outname):
1375 keys = [ k for k in wordmap ]
1376 keys.sort(key = lambda x: x.lower())
1377 size = len(keys)
1378 index = 0
1379 pc = self.progress(size)
1380 with codecs.open(outname, 'w', encoding = 'utf-8') as fp:
1381 for key in keys:
1382 pc.next()
1383 word = key.replace('</>', '').replace('\n', ' ')
1384 text = wordmap[key].replace('</>', '')
1385 if not isinstance(word, unicode):
1386 word = word.decode('gbk')
1387 if not isinstance(text, unicode):
1388 text = text.decode('gbk')
1389 fp.write(word + '\r\n')
1390 for line in text.split('\n'):
1391 line = line.rstrip('\r')
1392 fp.write(line)
1393 fp.write('\r\n')
1394 index += 1
1395 fp.write('</>' + ((index < size) and '\r\n' or ''))
1396 pc.done()
1397 return True
1398
1399 # 导入mdx源文件
1400 def import_mdict (self, filename, encoding = 'utf-8'):

Callers 1

compile_mdxMethod · 0.80

Calls 4

progressMethod · 0.95
nextMethod · 0.80
decodeMethod · 0.80
doneMethod · 0.80

Tested by

no test coverage detected