File: merge.py

package info (click to toggle)
opencc 1.1.1%2Bgit20200624%2Bds2-10
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 4,288 kB
  • sloc: cpp: 5,688; python: 348; javascript: 133; makefile: 101; sh: 58
file content (28 lines) | stat: -rwxr-xr-x 693 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import codecs
import sys

from common import sort_items

if len(sys.argv) < 4:
    print("Merge and sort all text dictionaries")
    print(("Usage: ", sys.argv[0], "[input1] [input2] ... [inputN] [output]"))
    exit(1)

all_lines = []
for i in range(1, len(sys.argv) - 1):
    input_file = codecs.open(sys.argv[i], "r", encoding="utf-8")
    for line in input_file:
        all_lines += line
    input_file.close()
    all_lines += '\n'

output_filename = sys.argv[-1]
output_file = open(output_filename, "wb")
for line in all_lines:
    output_file.write(line.encode('utf-8'))
output_file.close()

sort_items(output_filename, output_filename)