def traduceEplan(cadenaEntrada): """esta funcion va a devolver la cadena compuesta y traducida a partir de una cadena de entrada""" #print "----> " + str(cadenaEntrada) cadenaEntrada = str(cadenaEntrada) cadEs = "es_ES@" + cadenaEntrada + ';' #Primero traduccion al ingles apiTranslateEplan = """trnsl.1.1.20190308T091207Z.xxx""" tr = Translater() tr.set_key(apiTranslateEplan) tr.set_from_lang('es') tr.set_to_lang('en') tr.set_text(cadenaEntrada) cadEng = "en_US@" + tr.translate() + ";" # #Frances tr.set_to_lang('fr') tr.set_text(cadenaEntrada) cadFr = "fr_FR@" + tr.translate() + ";" cadFr = cadFr.replace("'", "''") #Aleman tr.set_to_lang('de') tr.set_text(cadenaEntrada) cadAle = "de_DE@" + tr.translate() + ";" # #Polaco # tr.set_to_lang('pl') # tr.set_text(cadenaEntrada) # cadPol = "pl_PL@" + tr.translate() + ";" cadenaSalida = cadEs + cadEng + cadFr + cadAle #+ cadPol return (cadenaSalida)
def traductionChained(utt, languages): tr = Translater() tr.set_key( 'trnsl.1.1.20200203T095917Z.30bf7af5cf091999.513bc5df39c8c45fd3cc2baa0ee4c8af7669202a' ) tr.set_text(utt) originLang = tr.detect_lang() tr.set_from_lang(originLang) tr.set_to_lang(languages[0]) tr.set_text(utt) utt = tr.translate() for i, lan in enumerate(languages): tr.set_from_lang(lan) if i < len(languages) - 1: tr.set_to_lang(languages[i + 1]) else: tr.set_to_lang(originLang) utt = tr.translate() tr.set_text(utt) #print(utt) return utt
def batcher(params, batch): import tensorflow as tf import tensorflow_hub as hub import re import seaborn as sns import matplotlib.pyplot as plt import numpy as np import os from yandex.Translater import Translater tr = Translater() tr.set_key( 'trnsl.1.1.20190129T181632Z.6ad260c3f03e55a5.ae512973f3fa9c42fec01e4218fb4efd03a61a1b' ) # Api key found on https://translate.yandex.com/developers/keys tr.set_from_lang('ru') tr.set_to_lang('en') module_url = "https://tfhub.dev/google/universal-sentence-encoder/2" embed = hub.Module(module_url) l = len(batch) for i in range(l): tr.set_text(batch[i]) sentence = tr.translate() batch[i] = sentence messages = batch with tf.Session() as session: session.run( [tf.global_variables_initializer(), tf.tables_initializer()]) message_embeddings = session.run(embed(messages)) embeddings = format(message_embeddings) return embeddings
def translate(): tr = Translater() tr.set_key('Insert_your_API_Key_Here') # Api key found on https://translate.yandex.com/developers/keys text_to_translate = 'شركة ذات مسؤولية محدودة' tr.set_text(text_to_translate) tr.set_from_lang('ar') tr.set_to_lang('en') translated_txt = tr.translate() print(translated_txt)
def translater(self): ru_str = self.ru_str tr = Translater() tr.set_key(self.token) tr.set_from_lang("ru") tr.set_to_lang("en") tr.set_text(ru_str) en_str = tr.translate() self.result = en_str print("Перевод:", self.result)
def traduceCarTec(cadenaEntrada): apiTranslateEplan = """trnsl.1.1.20190308T091207Z.xxx""" tr = Translater() tr.set_key(apiTranslateEplan) tr.set_from_lang('es') tr.set_to_lang('en') f.write("===> TraduceCarTec: " + str(cadenaEntrada) + str(type(cadenaEntrada))) tr.set_text(cadenaEntrada) cadEng = tr.translate() return (cadEng)
class Translate: def __init__(self): self.tin = Translater() self.tin.set_key("#your yandex id here") def translate(self, text, target): try: self.tin.set_to_lang(target) self.tin.set_text(text) self.tin.set_from_lang(self.tin.detect_lang()) self.r = self.tin.translate() return self.r except: print("Translate Failed.")
def init(update, context): bot = context.bot message_var = update.message.text[8:] try: tr = Translater() tr.set_key( Config.YANDEX_API ) # Api key found on https://translate.yandex.com/developers/keys tr.set_text(message_var) tr.set_from_lang('it') tr.set_to_lang('en') bot.send_message(update.message.chat_id, tr.translate()) except: bot.send_message(update.message.chat_id, text="Perfavore inserisci una frase.")
def translate(self, text, lanFrom, lanTo): if self.times != 0: tr = Translater() tr.set_key(secretKey) if re.search(r'[А-я]', text): tr.set_from_lang('ru') tr.set_to_lang('en') else: tr.set_from_lang('en') tr.set_to_lang('ru') if text != "": tr.set_text(text) textboxR.delete('1.0', "end-1c") textboxR.insert("1.0", tr.translate()) self.times += 1
def get_weather(city): token = '<your_token>' if city != '': translator = Translater(token, city, 'ru', 'en') translated = translator.translate().lower().replace(' ', '-') else: translated = 'moscow' url = 'https://yandex.ru/pogoda/' + translated response = requests.get(url) markup = BeautifulSoup(response.content, 'html.parser') try: weather_in_city = markup.find_all('div', {'class': 'main-title__title-wrap'})[0].text\ + ':' except IndexError: return 'Неправильный параметр команды' temperature = markup.find('span', {'class': 'temp__value'}).text + '°' weather_condition = markup.find('div', {'class': 'link__condition'}).text feels_like = markup.find('dt', {'class': 'term__label'}).text feels_like_temperature = markup.find_all( 'span', {'class': 'temp__value'})[1].text + '°' sense = feels_like + ' ' + feels_like_temperature humidity = 'Влажность: ' + markup.find_all( 'dd', {'class': 'term__value'})[3].text pressure = 'Давление: ' + markup.find_all( 'dd', {'class': 'term__value'})[-2].text try: # может быть 'Штиль', а не направление ветра wind_direction = markup.find('abbr', {'class': 'icon-abbr'})['title'] except TypeError: wind_direction = 'Ветер: ' # просто красиво форматирую вывод wind_condition = markup.find_all('dd', {'class': 'term__value'})[2].text.strip('СЮЗВ') +\ wind_direction[7:].title() wind = wind_direction[:7] + wind_condition return '\n'.join((weather_in_city, weather_condition, temperature, sense, humidity, pressure, wind))
import locale from yandex.Translater import Translater tr=Translater() locale.setlocale(locale.LC_ALL, '') #фиксит проблему с библиотекой яндекса api_key="trnsl.1.1.20200309T060830Z.344d9b14a5d60014.73173e69fc28c824b2288d084ca8e11617d260e1" query='boss' tr.set_key(api_key) tr.set_from_lang('en') tr.set_to_lang('ru') tr.set_text(query) result=tr.translate() speak(result)
from yandex.Translater import Translater tr = Translater() tr.set_key( 'trnsl.1.1.20200119T075806Z.ba2fc76141b64141.3739322923782504e521bd76c8903e90835cb864' ) tr.set_from_lang('en') tr.set_to_lang('ta') tr.set_text("rice crop field few weeks after sowing of seeds.") txt = tr.translate()
print("OCR TEXT") print("========") print("Raw:") print("{}\n".format(text)) print("Corrected:") corrected = text.replace("|", "I") corrected = corrected.replace("1", "l") corrected = corrected.replace("0", "O") corrected = spell.correction(corrected) print("{}\n".format(corrected)) # Translation translater.set_text(corrected) translation = translater.translate() print("Translated:") print("{}\n".format(translation)) img = Image.new('RGB', (roiW, roiH), color=(255, 255, 255)) font_color = (0, 0, 0) font_size = 12 d = ImageDraw.Draw(img) unicode_font = ImageFont.truetype("DejaVuSans.ttf", font_size) wrapped = textwrap.fill(translation, int(roiW / 8)) print("Wrapped:") print("{}\n".format(wrapped)) d.text((4, 4), wrapped, font=unicode_font, fill=font_color)
def sendEmail(target_email,url,tmrange,etype): df = pd.read_csv('feedback-256010.csv') edf = pd.read_csv('email_records.csv') if url == "EMEA": csites = ["cs_CZ","en_UK","nl_BE","da_DK","en_ZA","nl_NL","de_AT","es_ES","pl_PL","de_CH","fr_BE","pt_pt","de_DE","fr_CH","ru_RU","en_IE","fr_FR","sv_SE","en_IL","it_IT","tr_TR","en_MDE"] down_df = df[df['Source URL'].str.contains('|'.join(csites))] elif url == "North America": csites = ["en_NA"] down_df = df[df['Source URL'].str.contains('|'.join(csites))] elif url == "APAC": csites = ["zh_CN","ja_JP","zh_TW","en_SEA","ko_KR","en_AU","en_NZ","en_IN"] down_df = df[df['Source URL'].str.contains('|'.join(csites))] elif url == "LAR": csites = ["en_CAR","es_CL","es_PE","es_CAR","es_CO"] down_df = df[df['Source URL'].str.contains('|'.join(csites))] elif url == "rockwellautomation.com/search": csites = ['rockwellautomation.com/search','rockwellautomation.com/my/search'] down_df = df[df['Source URL'].str.contains('|'.join(csites))] else: down_df = df[df['Source URL'].str.contains(url)] today = datetime.now() timzo = pytz.timezone('US/Eastern') today = timzo.localize(today) week_prior = today - timedelta(weeks=tmrange) down_df['Date Submitted'] = pd.to_datetime(down_df['Date Submitted']) down_df['Date Submitted']=down_df['Date Submitted'].dt.tz_localize(tz='US/Eastern', nonexistent='shift_forward') date_df = down_df.loc[down_df['Date Submitted'] >= week_prior] #Cancel if no feedback at all in past week #if date_df.empty == True: #print("No data for time given, email not sent for "+str(url)) #return testemail = MIMEMultipart() sender_email = "*****@*****.**" pw = "Ao1HO2RO3" #target_email = "*****@*****.**" testemail["From"] = sender_email testemail["To"] = target_email testemail["Subject"] = "Hotjar feedback from "+week_prior.strftime("%m/%d")+" to "+ today.strftime("%m/%d")+" | "+str(url) if etype == 'Responses': mess_df=date_df.loc[date_df["Message"].notna()] mess_df = mess_df.drop(columns=['Number',"User","OS"]) htmlbod = '<html><body><h1>Hotjar feedback over past '+str(tmrange)+' week(s) for '+str(url)+'</h1>' if mess_df.empty == True: htmlbod = '<html><body><p>No feedback responses for '+str(url)+' over '+str(tmrange)+' week(s).</p>' #Emjois: 5: 128522,1F60A 4: 128527, 1F60F 3: 128528, 1F610 2: 128530 1F612 1: 128544, 1F620 #Link : 128279, 1F517 emo = '128528' from yandex.Translater import Translater from langdetect import detect for row in mess_df.itertuples(): if str(row.Email)=="nan": email = '<b>(unknown)</b>' else: email = '<b>'+str(row.Email)+'</b>' if row._7==1: emo='128544' elif row._7==2: emo='128530' elif row._7==3: emo='128528' elif row._7==4: emo='128527' elif row._7==5: emo='128522' try: detlan = detect(str(row.Message)) except: detlan = 'en' if detlan == 'en': htmlbod = htmlbod+'<p><q>'+str(row.Message)+'</q></p><p>&#'+emo+email+' on '+row._1.strftime("%m/%d/%Y, %H:%M:%S")+" | "+str(row.Country)+" | "+str(row.Browser)+" on "+str(row.Device)+'</p><a href='+str(row._3)+'>🔗'+str(row._3)+'</a><hr>' else: try: tr = Translater() tr.set_key('trnsl.1.1.20200326T171128Z.c6e42851517b0a0a.363c0f12f70ef655b2ea466b33e40856c53df6c8') tr.set_text(str(row.Message)) tr.set_to_lang('en') mtrans = tr.translate() except: mtrans = "Translation failed." htmlbod = htmlbod+'<p><q>'+str(row.Message)+'</q></p><p>Translation attempt: <q>'+mtrans+'</q></p><p>&#'+emo+email+' on '+row._1.strftime("%m/%d/%Y, %H:%M:%S")+" | "+str(row.Country)+" | "+str(row.Browser)+" on "+str(row.Device)+'</p><a href='+str(row._3)+'>🔗'+str(row._3)+'</a><hr>' htmlbod = htmlbod + '</body></html>' testemail.attach(MIMEText(htmlbod, "html")) if etype == 'Visualizations': histfig = px.histogram(date_df, x='Date Submitted', color='Emotion (1-5)', title='Feedback Responses for '+str(url), opacity=0.8, category_orders={'Emotion (1-5)':[1,2,3,4,5]}, color_discrete_map={1:"#e83b3a",2:"#c97d7d",3:"#BAB0AC",4:"#99bd9c",5:"#4cba76"}, nbins=20 ) histfig.update_layout(xaxis_tickformat='%d %B (%a)', xaxis=dict(dtick=86400000.0)) histfig.write_image('histfigtest.png') counfig = px.histogram(date_df, y='Country', color='Emotion (1-5)', title='Breakdown by Country for url given', opacity=0.8, orientation = 'h', height = 1000, category_orders={'Emotion (1-5)':[1,2,3,4,5]}, color_discrete_map={1:"#e83b3a",2:"#c97d7d",3:"#BAB0AC",4:"#99bd9c",5:"#4cba76"}, #nbins=20 ).update_yaxes(categoryorder="total ascending") counfig.write_image('counfig.png') apdate_df=date_df apdate_df['feedback_count']= apdate_df['Source URL'].map(apdate_df['Source URL'].value_counts()) bad_df = apdate_df.loc[(apdate_df['Emotion (1-5)'] == 1) | (apdate_df['Emotion (1-5)'] == 2)] intr_df = bad_df[bad_df.duplicated(subset='Source URL', keep=False)] bdap_df=intr_df bdap_df['negative_feedbacks']= bdap_df['Source URL'].map(bdap_df['Source URL'].value_counts()) intrfig = px.scatter(bdap_df, title='Pages of interest (Which pages are getting lots of bad feedback?)', y='Source URL', x='negative_feedbacks', color='negative_feedbacks', text='feedback_count', color_continuous_scale=px.colors.sequential.YlOrRd, size='feedback_count') intrfig.update_layout(margin=dict(l=500,r=10,t=40,b=20),xaxis=dict(dtick=1)) intrfig.layout.coloraxis.showscale = False dd_df = bdap_df.drop_duplicates(subset='Source URL', keep='first') nlarg_df = dd_df.nlargest(5,['negative_feedbacks']) with open('histfigtest.png', 'rb') as f: # set attachment mime and file name, the image type is png mime = MIMEBase('image', 'png', filename='img1.png') # add required header data: mime.add_header('Content-Disposition', 'attachment', filename='img1.png') mime.add_header('X-Attachment-Id', '0') mime.add_header('Content-ID', '<0>') # read attachment file content into the MIMEBase object mime.set_payload(f.read()) # encode with base64 encoders.encode_base64(mime) # add MIMEBase object to MIMEMultipart object testemail.attach(mime) with open('counfig.png', 'rb') as f: # set attachment mime and file name, the image type is png mime = MIMEBase('image', 'png', filename='img2.png') # add required header data: mime.add_header('Content-Disposition', 'attachment', filename='img2.png') mime.add_header('X-Attachment-Id', '1') mime.add_header('Content-ID', '<1>') # read attachment file content into the MIMEBase object mime.set_payload(f.read()) # encode with base64 encoders.encode_base64(mime) # add MIMEBase object to MIMEMultipart object testemail.attach(mime) with open('intrfig.png', 'rb') as f: # set attachment mime and file name, the image type is png mime = MIMEBase('image', 'png', filename='img3.png') # add required header data: mime.add_header('Content-Disposition', 'attachment', filename='img3.png') mime.add_header('X-Attachment-Id', '2') mime.add_header('Content-ID', '<2>') # read attachment file content into the MIMEBase object mime.set_payload(f.read()) # encode with base64 encoders.encode_base64(mime) # add MIMEBase object to MIMEMultipart object testemail.attach(mime) embimg = '<html><body><h1>HotJar Report</h1>'+'<p><img src="cid:0"></p>'+'<img src="cid:1"></p>'+'<img src="cid:2"></p>'+'</body></html>' testemail.attach(MIMEText(embimg, 'html','utf-8')) session = smtplib.SMTP('smtp.gmail.com', 587, None, 30) session.starttls() session.login(sender_email, pw) session.set_debuglevel(1) text = testemail.as_string() session.sendmail(sender_email, target_email, text) session.quit() rec_dict = {"Date":today, "Recipient":target_email, "URL":url, "Email_type":etype} nedf = pd.DataFrame(rec_dict, index=[0]) upd_edf = edf.append(nedf, ignore_index = True) upd_edf.to_csv('email_records.csv', index = False) st.write("Email for "+str(url)+" sent to "+str(target_email))
ges = test[0:n - 0] # print("Pengurangan Character :",ges) # toLowerCase Character gas = ges.strip() blob = clean_tweet(gas) hasil = stemmer.stem(blob) print("Lowering Case :", hasil) # Clean Tweets blob1 = str(hasil) print("Tweet Bersih :", blob1) # Translate Tweets tr.set_text(blob1) bersih = tr.translate() kedas = TextBlob(bersih) print("Translate Tweet :", bersih) print( "==============================================================================================================================" ) # Variable After Cleanning Tweets # mongo = { # "id": row["id"], # "created_at": row["created_at"], # "username": row["username"], # "followers": row["followers"], # "text": hasil, # "source": row["source"], # "url":row["url"],
# IMPORT THE YANDEX TRANSLATE API ENGINE TO OUR PYTHON APP SCRIPT from yandex.Translater import Translater # APP SET NAME AND VERSION | INSERT YOUR APP DETAILS, SUCH AS NAME AND VERSION print('Welcome to landRev | appDrew Development') # APP INITIALIZE THE YANDEX ENGINE TRANSLATOR tr = Translater() # APP INITIALIZE THHE API KEY FOR YANDEX ENGINE TRANSLATOR | INSERT YOUR API KEY BELLOW PLEASE. tr.set_key('YOUR YANDEX API KEY HERE') # APP SET THE MAIN LANGUAGE | INSERT YOUR MAIN LANGUAGE "FROM WHAT LANGUAGE TO TRANSLATE" tr.set_from_lang('en') # APP SET the TRANSLATION LANGUAGE | INSERT YOUR TRANSLATION LANGUAGE WITH LANG CODE tr.set_to_lang('es') INPUT_TEXT_DATA = input('What do you would like to translate ? : ') #SET THE INPUT_TEXT_DATA FOR TANSLATOR ENGINE TO TRANSLATE THE STRINGS tr.set_text(INPUT_TEXT_DATA) #PRINT OUT THE TRANSLATED DATA RESULTS results = tr.translate() print(results)