python開発翻訳プログラム
たくさん言わないで、コードをつけます!!!
#!/usr/bin/env python
#coding: utf-8
import urllib,re,json
def input_content(url): # url( AIP)
while True:
content = raw_input(' :') #
if str.strip(content) == '': #
continue #
elif content == 'q' or content == 'Q': # Q q
exit()
print '\033[31m ......\033[0m'
url = url+content # url
return url # url
def html(data): #
for i in data:
RE = re.compile(r'translation.*?\]') #
list_lost = re.findall(RE,i) #
lost = list_lost[0].split(':')[1] #
result = json.loads(lost) #
print result[0]+'
' #
if __name__ == '__main__':
print '\033[33m Q q \033[0m
' #
while True:
try:
url = 'http://fanyi.youdao.com/openapi.do?keyfrom=huyuanpy&key=902574943&type=data&doctype=json&version=1.1&q='
# API
address = input_content(url) #
data = urllib.urlopen(address) # ,
html(data) #
except:
print '\033[31m ......\033[0m
'
exit()