-
Notifications
You must be signed in to change notification settings - Fork 0
/
olla.py
executable file
·81 lines (64 loc) · 1.86 KB
/
olla.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
#!/bin/env python
import sys
import imp
import json
def dicts(base=''):
print base + 'dicts.py'
d = imp.load_source('', base + 'dicts.py')
return json.dumps(d.dicts)
def get_dict(lang, wtypes=None, wtype=None, base=''):
d = imp.load_source('dict_dst', base + lang)
print base + lang
if wtype and wtypes:
out = {}
print base + 'wtypes.py'
t = imp.load_source('dict_typ', base + wtypes)
for i in d.dictionary.keys():
if t.dictionary[i] == wtype:
out[i] = d.dictionary[i]
d.dictionary = out
return json.dumps(d.dictionary)
def translate(word, src, dst, base=''):
print base + src
src = imp.load_source('dict_src', base + src)
if type(dst) == type(""):
dst = [dst]
out = None
for d in dst:
try:
d = imp.load_source('dict_dst', base + d)
out = d.dictionary[word]
except KeyError:
continue
if out:
break
if out == None:
out = src.dictionary[word]
return json.dumps({"word": word,
"src": src.dictionary[word],
"dst": out})
def words(lang, base=''):
d = imp.load_source('dict', base + lang)
out = ''
#n = d.dictionary.keys()
n = d.dictionary.keys()
n.sort()
for i in n:
out += "%d|%s\n" % (i, d.dictionary[i])
return out
def word(word, dct, base=''):
out = ''
for d in dct:
try:
d = imp.load_source('dct', base + d)
out = d.dictionary[word]
except KeyError:
continue
if out:
break
return out
if __name__ == "__main__":
base = 'dicts/'
#print dicts(base)
#print get_dict(sys.argv[1], sys.argv[2], sys.argv[3], base)
print translate(int(sys.argv[1]), sys.argv[2], sys.argv[3:], base)