-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtranslate
45 lines (40 loc) · 1.1 KB
/
translate
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
#!/usr/bin/env python3
# -*- coding=UTF8 -*-
from translate import Translator
from termcolor import colored as color
import sys
import os
def Get_command_variable(self):
o = sys.argv[self]
return o
def translate_to_zh(self):
translator= Translator(to_lang="zh")
translation = translator.translate("%s" % self)
return translation
class main():
def call_main_mode(self=0):
print(color(translate_to_zh(Get_command_variable(1)),"green"))
pass
def call_command_mode(self=0):
result = os.popen(Get_command_variable(2))
print(color(translate_to_zh(result.read()),"green"))
pass
def main(self=0):
if Get_command_variable(1) == "-c" or Get_command_variable(1) == "--command":
main.call_command_mode()
else:
main.call_main_mode()
pass
pass
if __name__ == "__main__":
is_ok=True
try:
Get_command_variable(1)
except IndexError:
print(color("Error:不支持无参数运行!","red"))
is_ok=False
pass
if is_ok:
main.main()
pass
pass