forked from igsekor/pyspelling-any
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extract-lang.py
64 lines (55 loc) · 1.76 KB
/
extract-lang.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
import yaml
import sys
def remove_duplicates(l):
return list(dict.fromkeys(l))
def find_languges(yaml, starting_list = []):
lang_list = starting_list
if isinstance(yaml, dict):
for k in yaml.keys():
if k == 'lang' or k == 'd':
lang_list.append(yaml[k])
elif isinstance(yaml[k], list):
for l in yaml[k]:
find_languges(l, lang_list)
elif isinstance(yaml[k], dict):
find_languges(yaml[k], lang_list)
else:
pass
elif isinstance(yaml, list):
for l in yaml:
find_languges(l, lang_list)
else:
pass
return lang_list
def find_engines(yaml, starting_list = []):
engine_list = starting_list
if isinstance(yaml, dict):
for k in yaml.keys():
if k == 'aspell' or k == 'hunspell':
engine_list.append(k)
elif isinstance(yaml[k], list):
for l in yaml[k]:
find_engines(l, engine_list)
elif isinstance(yaml[k], dict):
find_engines(yaml[k], engine_list)
else:
pass
elif isinstance(yaml, list):
for l in yaml:
find_engines(l, engine_list)
else:
pass
return engine_list
with open(sys.argv[1], 'r') as file:
yaml = yaml.load(file, Loader=yaml.FullLoader)
lang_list = find_languges(yaml)
engine_list = find_engines(yaml)
output_list = []
output_string = ''
for e in engine_list:
for l in lang_list:
output_list.append(e + '-' + l)
for l in remove_duplicates(output_list):
output_string += ' ' + l
output_string = output_string.replace('_', '-')
print(output_string.lower())