-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdictionary.py
executable file
·51 lines (39 loc) · 1.14 KB
/
dictionary.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
import json
from os.path import dirname, abspath, join
from Dictionary_APIs import iciba, youdao, renren
dictionaries = {
'iciba': iciba.Iciba,
'youdao': youdao.Youdao,
'renren': renren.Renren,
}
class DictionaryAPI(object):
def __init__(self, word='', service=dictionaries['iciba']):
self.service = service(word)
def search(self):
self.service.search()
def display(self):
self.service.display()
if __name__ == '__main__':
base_dir = dirname(abspath(__file__))
with open(join(base_dir, 'config.json')) as file:
configs = json.load(file)
default_dictionary = configs.get('default_dictionary')
service = {}
if default_dictionary:
service['service'] = dictionaries[default_dictionary]
if len(sys.argv) == 3:
kwargs = {
'word': sys.argv[1],
'service': dictionaries.get(sys.argv[2])
}
else:
kwargs = {
'word': sys.argv[1],
}
kwargs.update(service)
dictionary = DictionaryAPI(**kwargs)
dictionary.search()
dictionary.display()