-
Notifications
You must be signed in to change notification settings - Fork 3
/
launcher.py
97 lines (75 loc) · 3.68 KB
/
launcher.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import sys
import string
import argparse
from dict_generator import Generator
from format_generator import FormatGenerator
from fullname_parsing import Parser
from utils import get_file_contents
if __name__== "__main__":
parser = argparse.ArgumentParser(description='Generate list of nicknames by certain format')
parser.add_argument('--formating', type=str, nargs='+',
help='format string (use {name}, {surname[2]}, {patronymic[5]} and constant strings)')
parser.add_argument('--formating-file', type=str, dest="formating_file",
help='file with different formats')
parser.add_argument('--name', type=str, nargs='+',
help='first name (multiple, space-delimited)')
parser.add_argument('--name-file', type=str, dest='name_file',
help='first names file')
parser.add_argument('--surname', type=str, nargs='+',
help='surname (multiple, space-delimited)')
parser.add_argument('--surname-file', type=str, dest="surname_file",
help='surnames file')
parser.add_argument('--patronymic', type=str, nargs='+',
help='patronymic (multiple, space-delimited)')
parser.add_argument('--patronymic-file', type=str, dest="patronymic_file",
help='patronymics file')
parser.add_argument('--fullname-file', type=str, dest="fullname_file",
help='fullname file (\n delimited entries)')
parser.add_argument('--fullname-format', type=str, dest="fullname_format",
help='fullname file format, will be parsed into list of primitive parameters, e.x. name:surname:patronymic')
parser.add_argument('--config', type=str, default="transliteration.json", dest="transliteration_config",
help='transliteration config file')
args = parser.parse_args()
config = args.transliteration_config
if args.formating_file:
formatings = get_file_contents(args.formating_file)
else:
formatings = args.formating
if args.name and args.name_file:
print("You should specify either --name of --name-file, not both")
sys.exit(1)
if args.surname and args.surname_file:
print("You should specify either --surname of --surname-file, not both")
sys.exit(1)
if args.patronymic and args.patronymic_file:
print("You should specify either --patronymic of --patronymic-file, not both")
sys.exit(1)
if args.fullname_file and (
args.name or args.name_file or
args.surname and args.surname_file or
args.patronymic and args.patronymic_file
):
print("You can specify either --fullname-file or {--name, --surname, --patronymic}")
sys.exit(1)
if args.fullname_file:
if not args.fullname_format:
print("Specify a format using --fullname-format 'name:surname:patronymic' for example")
sys.exit(1)
p = Parser(args.fullname_file, args.fullname_format).parse_fullname_file()
names = p.get('name', None)
surnames = p.get('surname', None)
patronymics = p.get('patronymic', None)
else:
if args.name_file:
names = get_file_contents(args.name_file)
else:
names = args.name
if args.surname_file:
surnames = get_file_contents(args.surname_file)
else:
surnames = args.surname
if args.patronymic_file:
patronymics = get_file_contents(args.patronymic_file)
else:
patronymics = args.patronymic
print('\n'.join(Generator(formatings, config, names, surnames, patronymics).build_formatted()))