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.")
예제 #2
0
 def __init__(self,to_lang='es',from_lang='en'):
     token = "TOKEN" #get here https://translate.yandex.com/developers/keys
     tr = Translater()
     tr.set_key(token)
     tr.set_to_lang(to_lang)
     tr.set_from_lang(from_lang)
     self.from_lang_default = from_lang
     self.tr = tr
예제 #3
0
def init(update, context):
    bot = context.bot
    var_messagge = update.message.text[6:]
    # Variables
    currenttimestr = 'Tempo attuale a '
    citynotfoundstr = 'Non ho trovato la città'
    tempunit = 'celsius'
    tempstr = 'C°'
    lang = 'it'
    # Code
    try:
        tr = Translater()
        tr.set_key(Config.YANDEX_API)
        tr.set_from_lang('en')
        tr.set_to_lang(lang)
        weather = pyowm.OWM(Config.OPENWEATHER_API).weather_at_place(
            var_messagge.lower().capitalize()).get_weather()
        status = weather.get_status()
        desc = weather.get_detailed_status()
        for a, b in weather.get_temperature(unit=tempunit).items():
            if a == 'temp':
                temp = b
            if a == 'temp_min':
                mintemp = b
            if a == 'temp_max':
                maxtemp = b

        def sendweathermsg(icon):
            msgtext = currenttimestr + var_messagge.lower().capitalize(
            ) + ':\n\n'
            if icon == '':
                msgtext = msgtext + desc.capitalize()
            else:
                msgtext = msgtext + icon + ' ' + desc.capitalize() + ' ' + icon
            msgtext = msgtext + '\nHumidity: ' + str(weather.get_humidity(
            )) + '%\nTemp: ' + str(temp) + tempstr + ', Min Temp: ' + str(
                mintemp) + tempstr + ', Max Temp: ' + str(maxtemp) + tempstr
            tr.set_text(msgtext)
            bot.send_message(update.message.chat_id,
                             text=tr.translate(),
                             parse_mode='HTML')

        if status == 'Clouds':
            sendweathermsg('☁️')
        elif status == 'Clear':
            sendweathermsg('☀️')
        elif status == 'Rain':
            sendweathermsg('🌧')
        elif status == 'Drizzle':
            sendweathermsg('🌧')
        elif status == 'Mist':
            sendweathermsg('🌫')
        else:
            sendweathermsg('')
    except:
        bot.send_message(update.message.chat_id,
                         text=citynotfoundstr,
                         parse_mode='HTML')
예제 #4
0
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))
from newspaper import Article
import nltk, re, pprint
from nltk import word_tokenize
import string
from yandex.Translater import Translater

tr = Translater()

tr.set_key(
    'trnsl.1.1.20190620T080928Z.059272b876400ab5.db9848757da3b1698721fef656db05d4903c4d1b'
)

tr.set_from_lang('en')
tr.set_to_lang('tr')

nltk.download('words')
nltk.download('stopwords')
nltk.download('averaged_perceptron_tagger')

#get stopwords, corpus-words

from nltk.corpus import words
from stop_words import get_stop_words
from nltk.corpus import stopwords

stop_words = list(get_stop_words('en'))  #Have around 900 stopwords
nltk_words = list(stopwords.words('english'))  #Have around 150 stopwords
stop_words.extend(nltk_words)


def fetch_words_from_news(url):
        Generates a json from the list return by get_tryalgo_descriptions(),
        and saves it in data/description.json

        :param translate: boolean passed to get_tryalgo_descriptions()
    """

    description_obj = get_tryalgo_descriptions(translate=translate)

    description_file = os.path.join("..", "data", "description.json")

    with open(description_file, "w") as f:
        f.write(json.dumps(description_obj))


if __name__ == "__main__":

    if len(sys.argv) > 2:
        args_error()
    if len(sys.argv) == 2:
        if sys.argv[1] != "--no-translation":
            args_error()
        generate_json(translate=False)
    else:

        tr = Translater()
        yandex_key = get_yandex_key()
        tr.set_key(yandex_key)
        tr.set_from_lang('en')
        tr.set_to_lang('fr')

        generate_json(translate=True)
예제 #7
0
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)

예제 #8
0
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)
예제 #9
0
from fuzzywuzzy import process
from yandex.Translater import Translater

tr = Translater()
tr.set_key('trnsl.1.1.20191110T032857Z.5cb504ab3196bc0f.e222fb57077985f5bc174f9f7b8ff5622b83d7ed') # Api key found on https://translate.yandex.com/developers/keys

def tran(text_from_user, to_lang, tr):
    tr.set_from_lang('th')
    tr.set_to_lang('en')
    tr.set_text(text_from_user)
    text_output = tr.translate()
    return (text_output)

def check_lang(Input):
    corpus = {
        'fr' : ['france','ฝรั่งเศส'], #90
        'de' : ['german','deutsch','เยอรมันนี'], #36
        'en' : ['english','อังกฤษ','อิ้ง'] #67
    }
    best_match = ''
    highest_score = 0
    for key,value in corpus.items():
        out = process.extractOne(Input, value)
        if out[1] > highest_score:
            highest_score = out[1]
            best_match = key
        else :
            continue
    return best_match

# while True:
예제 #10
0
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)
예제 #11
0
import requests
from joblib import load
from numpy import isnan
from sklearn.ensemble import RandomForestClassifier
from yandex.Translater import Translater, TranslaterError

from gras import ROOT
from gras.base_miner import BaseMiner
from gras.errors import YandexError, YandexKeyError
from gras.identity_merging.utils import (damerau_levenshtein as dl,
                                         gen_count_dict, gen_feature_vector,
                                         monge_elkan, read_csv)
from gras.utils import exception_handler

logger = logging.getLogger("main")
translator = Translater()

TOTAL_TRANSLATED = 0
TERMS = [
    "jr", "junior", "senior", "sr", "2nd", "ii", "iii", "iv", "v", "vi", "dr",
    "mr", "mrs", "ms", "phd", "prof", "professor", "miss", "mx", "sir", "mme",
    "msgr", "md", "server", "fake", "none", "null", "anonymous", "support",
    "admin", "unknown", "root", "nobody", "ubuntu", "(no author)", "system",
    "<blank>", "user", "noreplycom"
]

EMAIL_REGEX = r"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)"


class Alias:
    """
 def __init__(self):
     self.tin = Translater()
     self.tin.set_key("#your yandex id here")
    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
from Sastrawi.Stemmer.StemmerFactory import StemmerFactory
from textblob import TextBlob
import re
import json

# Connection to MongoDB
myclient = pymongo.MongoClient("mongodb://localhost:27017/")
mydb = myclient["indonesia"]
mycol = mydb["test10"]

# Stemmer
factory = StemmerFactory()
stemmer = factory.create_stemmer()

# Translater
tr = Translater()
tr.set_key(
    'trnsl.1.1.20191105T142939Z.b7e2df135b69d172.03f8d4635086f151f8b025984598a17b9af20ca6'
)  # Api key found on https://translate.yandex.com/developers/keys
tr.set_from_lang('id')
tr.set_to_lang('en')


def _connect_mongo(host, port, username, password, db):
    """ A util for making a connection to mongo """

    if username and password:
        mongo_uri = 'mongodb://localhost:27017/' % (username, password, host,
                                                    port, db)
        conn = MongoClient(mongo_uri)
    else:
예제 #15
0
 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)
예제 #16
0
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.")
예제 #17
0
파일: raw.py 프로젝트: Raahul46/Agro-bharat
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()
예제 #18
0
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
예제 #19
0
from linebot import (LineBotApi, WebhookHandler)
from linebot.exceptions import (InvalidSignatureError)
from linebot.models import *
from yandex.Translater import Translater
from fuzzywuzzy import process  ## import fuzz

app = Flask(__name__)

from Config import DEVELOPEMENTCONFIG
from datetime import datetime
from Flex import Flex_output, Flex_database

line_bot_api = LineBotApi(DEVELOPEMENTCONFIG.CHANNEL_ACCESS_TOKEN)
handler = WebhookHandler(DEVELOPEMENTCONFIG.CHANNEL_SECRET)
user_session = {}  #database for correct user
tr = Translater()
tr.set_key(DEVELOPEMENTCONFIG.YANDEX_KEY
           )  # Api key found on https://translate.yandex.com/developers/keys

List_test = []


@app.route("/callback", methods=['POST'])
def callback():
    # get X-Line-Signature header value
    signature = request.headers['X-Line-Signature']

    # get request body as text
    body = request.get_data(as_text=True)
    print(body)
    app.logger.info("Request body: " + body)
예제 #20
0
#setup
from yandex.Translater import Translater
import sys,os
from keys import API_KEY
clear = lambda: os.system('cls')
filePath = sys.argv[1]

#opening files
wordSet = open(filePath,'r').read().split('\n')
wordSet_trd = open('translation.txt', 'w')

#setting up the API key
tr=Translater()
tr.set_key(API_KEY)

All_num = len(wordSet)
Done_num = 0

def translation(word):
    tr.set_from_lang('pl')
    tr.set_to_lang('en')
    tr.set_text(word)
    trd = tr.translate()
    return trd

#main
for word in wordSet:
    clear()
    print(str(Done_num) + "/" + str(All_num) + " done.")
    word_trd = translation(word)
    Done_num += 1
from wozzol import WozzolQuizUnit
import os
import requests

from yandex.Translater import Translater
tr = Translater()
# Api key found on https://translate.yandex.com/developers/keys
tr.set_key('trnsl.1.1.20200317T184210Z.859bd4e1e36decc9.54c5d73f715ded0f0b5e33e8f80d0eca61173b7d')
tr.set_from_lang('es')
tr.set_to_lang('en')


def translate_word(word):
    tr.set_text(word)
    translation = tr.translate()
    return translation


def convert_word_list_to_wozzol(word_list):
    with open('somefile.txt', 'a') as the_file:
        the_file.write('wozzol')
        the_file.write('Spanish : English')
        for word in word_list:
            the_file.write(f'{word.question} = {word.answer}')


def convert_wiktionary():
    file_path = os.path.join('web_pages', 'spanish_1000_frequency.html')
    # format from https://www.wozzol.nl/woordenlijsten
    text_file = open(file_path, encoding="utf-8")
    text_lines = text_file.readlines()
예제 #22
0
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)+'>&#128279'+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)+'>&#128279'+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))
예제 #23
0
# coding=UTF-8

import pandas as pd
from yandex.Translater import Translater
import time
import requests

tr = Translater()
tr.set_key('put Yandex translator key here')
tr.set_from_lang('en')
tr.set_to_lang('ru')

dfru = pd.read_csv('Names_List/FakeNameGenerator_ru.csv')
dfen = pd.read_csv('Names_List/FakeNameGenerator_en.csv')
ru_names = pd.read_csv('Names_List/final_merged_ru_names_list.csv')
# ru_fam = pd.read_csv('Names_List/russian_surnames.csv', delimiter=';', index_col=0)

ru_male_names = set(
    s.replace('ё', 'е').replace(chr(769), '').lower() for s in ru_names[ru_names['sex'] == 'male']['names'])

ru_male_surnames_endings = set(
    s.replace(chr(769), '')[-2:].replace('ё', 'е').lower() for s in dfru[dfru['Gender'] == 'male']['Surname'])

ru_female_names = set(
    s.replace('ё', 'е').replace(chr(769), '').lower() for s in ru_names[ru_names['sex'] == 'female']['names'])
ru_female_surnames_endings = set(
    s.replace(chr(769), '')[-2:].replace('ё', 'е').lower() for s in dfru[dfru['Gender'] == 'female']['Surname'])
ru_female_surnames_endings.remove('ов')

en_male_names = set(
    s.replace('ё', 'е').replace(chr(769), '').lower() for s in dfen[dfen['Gender'] == 'male']['GivenName'])
예제 #24
0
    return cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)


# Thresholding
def thresholding(image):
    return cv2.threshold(image, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1]


# Set enviroment variable with path to tesseract trained data
os.environ["TESSDATA_PREFIX"] = "data"

# Setup spellchecker
spell = SpellChecker()

# Setup translater
translater = Translater()
translater.set_key(args["apikey"])
translater.set_from_lang('en')
translater.set_to_lang('ru')

# Load the input image and grab the image dimensions
image = cv2.imread(args["image"])
orig = image.copy()
(origH, origW) = image.shape[:2]

# Set the new width and height and then determine the ratio in change
# for both the width and height
(newW, newH) = (args["width"], args["height"])
rW = origW / float(newW)
rH = origH / float(newH)
예제 #25
0
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)
예제 #26
0
from tkinter import *
from tkinter import scrolledtext
import pyowm
from yandex.Translater import Translater
trans = Translater()
owm = pyowm.OWM('4613a2063bd329d8886d085321fbf742')
weather_wind_azimut = ""


def clicked():
    txt.delete(1.0, END)
    trans.set_key(
        'trnsl.1.1.20190719T155509Z.1bbb471edc0c0bc1.0a6d2b3a0871e6a62f32efb3d559b0457b464c37'
    )
    trans.set_from_lang('en')
    trans.set_to_lang('ru')
    trans.set_default_ui('ru')
    observation = owm.weather_at_place(input1.get())
    w = observation.get_weather()
    weather_satus = w.get_detailed_status()
    weather_wind_speed = w.get_wind()['speed']
    weather_wind_deg = int(w.get_wind()['deg'])
    if 0 <= weather_wind_deg < 90:

        weather_wind_azimut = "Северный"
    elif 90 <= weather_wind_deg < 180:
        weather_wind_azimut = "Восточный"
    elif 180 <= weather_wind_deg < 270:
        weather_wind_azimut = "Южный"
    elif 270 <= weather_wind_deg < 359:
        weather_wind_azimut = "Западный"
예제 #27
0
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
예제 #28
0
def init_yandex_service():
    tr = Translater()
    tr.set_key(initdata.yandex_token())
    tr.set_from_lang('en')
    tr.set_to_lang('ru')
    return tr
예제 #29
0
def detect_language(texte):
    tr = Translater()
    tr.set_key(parameters.yandex_api_key())
    tr.set_text(texte)
    tr.set_hint("fr", "en")
    return tr.detect_lang()
예제 #30
0

#application = Flask(__name__)

import time
import cloudmersive_ocr_api_client
from cloudmersive_ocr_api_client.rest import ApiException
from pprint import pprint
import yake
import spacy
import pytextrank
from pymongo import MongoClient
from gensim.summarization.summarizer import summarize
from gensim.summarization import keywords
from yandex.Translater import Translater
tr = Translater()
tr.set_key(
    'trnsl.1.1.20200229T030530Z.d16dc45c4ba5761f.aebee0a45aab9956dae437936242065f92ab5b0b'
)

try:
    conn = MongoClient()
    print("Connected successfully!!!")
except:
    print("Could not connect to MongoDB")

# database
db = conn.database
collection = db.english_doc

collection.delete_many({})