-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWiktionaryCli.py
47 lines (35 loc) · 1.2 KB
/
WiktionaryCli.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
from errors import IllegalArgumentException
from compat import File
import sys
def PyWiktionaryCli():
"""
* Offers a command line interface to Wiktionary. You can type a word and
* after pressing <enter> the information of corresponding entries will
* be printed. In order to quit the interface just hit enter
"""
"""
# @param args path to parsed Wiktionary data
"""
if len(sys.argv) != 2:
raise IllegalArgumentException("Too few arguments. Required arguments: <PARSED-WIKTIONARY>")
PROMPT = "> "
END = ""
wktPath = sys.argv[1]
from api.WiktionaryFormatter import WiktionaryFormatter
formatter = WiktionaryFormatter.instance()
try:
from PyWKTL import PyWKTL
wkt = PyWKTL.openEdition(File("", wktPath))
while True:
line = input(PROMPT)
if line == END:
break
page = wkt.getPageForWord(line)
if page is None or page.getEntryCount() == 0:
print(line + " is not in Wiktionary")
else:
print(formatter.formatPage(page))
except EOFError:
print("exit")
if __name__ == "__main__":
PyWiktionaryCli()