-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
36 lines (30 loc) · 1.21 KB
/
main.py
File metadata and controls
36 lines (30 loc) · 1.21 KB
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
36
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("format", help="Format to conversion", type=str)
parser.add_argument("sql", help="Multitran SQL file", type=str)
parser.add_argument("-o", "--output", help="Output file", type=str)
parser.add_argument("--sort", help="Sort keys", action="store_true")
parser.add_argument("--indent", help="JSON Indent", type=int, default=None)
parser.add_argument("--ensure-ascii", help="JSON Ensure ASCII", action="store_true")
args = parser.parse_args()
if args.format == "json":
import multitran2json
import json
sort_keys = False
ensure_ascii = False
out = "file.json"
if args.sort:
sort_keys = True
if args.ensure_ascii:
ensure_ascii = True
if args.output:
out = args.output
# print(json.dumps(multitran2json.convert(args.sql),
# ensure_ascii=ensure_ascii, indent=args.indent, sort_keys=sort_keys))
with open(out, "w") as write_file:
json.dump(multitran2json.convert(args.sql),
ensure_ascii=ensure_ascii, indent=args.indent, sort_keys=sort_keys, fp=write_file)
print("Saved as", out)
else:
print("Unknown format", args.format)
parser.print_help()