Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def translate(text):
gs = goslate.Goslate()
id = text.split()
return gs.translate(text[3:], id[0])
import wolframalpha
import goslate
import numpy as np
from cv2 import cv
import win32api
########################## Initializers ##############################
wiki = WikiApi()
engine = pyttsx.init()
owm = pyowm.OWM('Enter API Key') ### Weather API key PYOWM
client = TwilioRestClient('Enter API Key','Enter User Key') ### Twilio Key
client_wolfram = wolframalpha.Client('Enter API Key - Wolfram')
rand=(randint(0,90000))
gs = goslate.Goslate()
############################Splash Screen############################
app = QtGui.QApplication(sys.argv)
splash_pix = QtGui.QPixmap('conti.jpg')
splash = QtGui.QSplashScreen(splash_pix)
splash.setMask(splash_pix.mask())
splash.show()
time.sleep(2)
splash.hide()
###########################Welcome Message############################
text2speak = "Welcome To Amelia 2.0"
engine.setProperty('rate', 180)
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[1].id)
engine.say(text2speak)
return
langs = parsed_args[0]
text = u" ".join(parsed_args[1:])
if u":" in langs:
split = langs.split(u":")
from_lang, to_lang = split[0], split[1]
else:
from_lang, to_lang = u"", langs
try:
translation = self.goslate.translate(text, to_lang, from_lang)
source.respond(u"[{}] {}".format(to_lang, translation))
except Error as e:
source.respond(u"Translation error: {}".format(e))
except Exception as e:
self.logger.exception("Translation error")
source.respond(u"Translation error: {}".format(e))
def send_google_translator(self, prepared_sub, source_language, target_language):
# Using Google API is not free so we can send sentences via browser for this Goslate module
# is written by ZHUO Qiang. For more information http://pythonhosted.org/goslate/#module-goslate
# More info about language abbreviation
# https://developers.google.com/translate/v2/using_rest#language-params
try:
gs = goslate.Goslate()
except:
print "Wait and send again"
time.sleep(5)
gs = goslate.Goslate()
return gs.translate(prepared_sub, target_language, source_language)
k_tar=open(gl.keyworddir,'a')
print >> k_tar,"<p>%s</p>" % text
k_tar.close()
#fp = file(gl.keyworddir)
#lines = []
#for line in fp: # 内置的迭代器, 效率很高
# lines.append(line)
#fp.close()
#lines.insert(0, "<p>%s</p>" % text) # 在第二行插入
#s = '\n'.join(lines)
#fp = file(gl.keyworddir, 'w')
#fp.write(s)
#fp.close()
#[google youdao]
if gl.Dict=="google":
gs = goslate.Goslate()
gl.lang=gs.detect(text)
g_tar=open(gl.googledir,'w+')
if gl.lang=='zh-CN':
basehtml="<title>Google Translate</title><p>Source Language: %s</p><p>Target Language : %s</p><p>Selected Text : %s</p><p>Target Text : %s</p><p>%s %s</p>"%(gl.lang,'en',text,gs.translate(text, 'en'),"%index%","%expand%")
else:
basehtml="<title>Google Translate</title><p>Source Language: %s</p><p>Target Language : %s</p><p>Selected Text : %s</p><p>Target Text : %s</p><p>%s %s</p>"%(gl.lang,'zh-CN',text,gs.translate(text, 'zh-CN'),"%index%","%expand%")
print >> g_tar,basehtml
g_tar.close()
gl.homeurl= "file://" + gl.googledir
if gl.Dict=="youdao":
#os.system("curl -m 5 -A \"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/37.0.2062.120 Chrome/37.0.2062.120 Safari/537.36\" -s -w %{http_code}:%{time_connect}:%{time_starttransfer}:%{time_total}:%{speed_download} -o \'" + gl.origindir +"\' \'" + url+ "\'") #获得网页(非代理)
os.system("curl -m 5 -s -w %{http_code}:%{time_connect}:%{time_starttransfer}:%{time_total}:%{speed_download} -o \'" + gl.origindir +"\' \'" + url+ "\'") #获得网页(非代理)
fusionyoudao.reconstruct(gl.func)
gl.homeurl="file://" + gl.resultdir #合成最终缓冲访问地址
if Alive==1:
window.settitle(gl.title)
try:
from urllib.request import build_opener, Request, HTTPHandler, HTTPSHandler
from urllib.parse import quote_plus, urlencode, unquote_plus
except ImportError:
from urllib2 import build_opener, Request, HTTPHandler, HTTPSHandler
from urllib import urlencode, unquote_plus, quote_plus
try:
unicode
except NameError:
unicode = str
class AdjustedGoslate(Goslate):
DICT = u'dict'
SENTENCE = u'sentence'
def translate(self, text, target_language, source_language=''):
if not target_language:
raise Error('invalid target language')
if not text.strip():
return u'', unicode(target_language)
GOOGLE_TRASLATE_URL = 'http://translate.google.com/translate_a/t'
GOOGLE_TRASLATE_PARAMETERS = {
'client': 'z',
'sl': source_language,
'tl': target_language,
def language(text, target=None, source=None):
target = target.lower() if target else "en"
source = source.lower() if source else "auto"
gs = goslate.Goslate()
languages = gs.get_languages()
if target not in languages:
reverse = dict((value.lower(), key) for key, value in languages.items())
target = reverse.get(target)
return gs.translate(text, target, source)
parser.add_option('-r', '--roman', action="store_true",
help='change translation writing to roman (e.g.: output pinyin instead of Chinese charactors for Chinese. It only valid for some of the target languages)')
options, args = parser.parse_args(argv[1:])
if not options.target_language:
print('Error: missing target language!')
parser.print_help()
return
writing = WRITING_NATIVE
if options.roman:
writing = WRITING_ROMAN
gs = Goslate(writing=writing)
import fileinput
# inputs = fileinput.input(args, mode='rU', openhook=fileinput.hook_encoded(options.input_encoding))
inputs = fileinput.input(args, mode='rb')
inputs = (i.decode(options.input_encoding) for i in inputs)
outputs = gs.translate(inputs, options.target_language, options.source_language)
for i in outputs:
sys.stdout.write((i+u'\n').encode(options.output_encoding))
sys.stdout.flush()
def send_google_translator(self, prepared_sub, source_language, target_language):
# Using Google API is not free so we can send sentences via browser for this Goslate module
# is written by ZHUO Qiang. For more information http://pythonhosted.org/goslate/#module-goslate
# More info about language abbreviation
# https://developers.google.com/translate/v2/using_rest#language-params
try:
gs = goslate.Goslate()
except:
print "Wait and send again"
time.sleep(5)
gs = goslate.Goslate()
return gs.translate(prepared_sub, target_language, source_language)