Beispiel #1
0
def assistant(command):
    if 'hey' in command:
        talk("hello")

    elif ('news' in command) or ('headlines' in command):
        try:
            news_headlines()
        except:
            talk("Sorry, something went wrong")

    elif 'weather' in command:
        try:
            weather_report()
        except:
            talk("Sorry, something went wrong")

    elif 'translate' in command:
        try:
            translate()
        except:
            talk("Sorry, something went wrong")

    elif 'wikipedia' in command:
        try:
            wiki_search()
        except:
            talk("Sorry, something went wrong")

    elif ('song' in command) or ('music' in command):
        try:
            play_music()
        except:
            talk("Sorry, something went wrong")

    elif ('download' in command) and ('video' in command):
        try:
            video_dwnld()
        except:
            talk("Sorry, something went wrong")

    elif ('stream' in command) and ('video' in command):
        try:
            video_stream()
        except:
            talk("Sorry, something went wrong")

    else:
        try:
            talk("Opening search result from google")
            google_search(command)
        except:
            talk("Sorry, something went wrong")
Beispiel #2
0
def ejec_ascendente():

    cont1 = editor.get("1.0", END)
    ast = analize(cont1)
    if ast != None:
        analizeAST(cont1)
        fileAugus = translate(ast)

        file1 = open('un-optimized.augus', 'w')
        file1.write(fileAugus)
        file1.close()

        from Optimizer import optimize

    else:
        fileAugus = ''

    global ts_debug, no_instruccion, waitForCommand, ejecucion_automatica
    ejecucion_automatica = 1
    cont = editor.get("1.0", END)
    waitForCommand = 0
    Inter.inicializarGUI(editor, consola)
    Inter.limpiarValores()
    Inter.inicializarEjecucionAscendente(fileAugus)
    Inter.inicializarTS()
    i = 0
    while i < len(Inter.instrucciones):
        if waitForCommand == 0 or waitForCommand == 2:  #0=Sin Entrada, 1=Esperando, 2=Comando Ingresado
            if i < len(Inter.instrucciones):
                is_asig = Inter.instrucciones[i]
                if isinstance(is_asig, Asignacion):
                    # COMANDO PARA LEER DE CONSOLA
                    if isinstance(is_asig.valor, Read) and waitForCommand == 0:
                        waitForCommand = 1
                        no_instruccion = i
                        return None
                #EJECUTAR INSTRUCCION
                instr_temp = Inter.ejecutarInstruccionUnitaria(1, i)
                if instr_temp is not None:
                    if instr_temp == -10:  # EXIT
                        i = len(Inter.instrucciones)
                    else:  #GOTO
                        i = instr_temp
                waitForCommand = 0
            else:
                MessageBox.showinfo("Finalizado",
                                    "Ultima instruccion ejecutada.")
        i = i + 1
Beispiel #3
0
def index():
    try:
        sentence = request.form['left-translation']
        matcher = int(request.form['algorithm'])
        dictionary = request.form['submit'].lower() + '.txt'
        isSunda = request.form['submit'] == 'Sunda'

        result, alternatives = translate(dictionary, sentence, matcher)

        return render_template('index.html',
                               sentence=sentence,
                               result=result,
                               alternatives=alternatives,
                               isSunda=isSunda)
    except:
        return render_template('index.html')
Beispiel #4
0
    def __get_forecast_from_weather__(self, weather, location):
        forecast_object = WeatherForecast()
        forecast_object.units = self.units
        forecast_object.fetch_datetime = datetime.now()
        forecast_object.location = location
        forecast_object.datetime = weather.get_reference_time(
            timeformat='date')

        forecast_object.icon = weather.get_weather_icon_name()
        forecast_object.air_humidity = str(weather.get_humidity())
        forecast_object.clouds = str(weather.get_clouds())
        forecast_object.short_description = translate(str(
            weather.get_status()))
        forecast_object.detailed_description = str(
            weather.get_detailed_status())
        forecast_object.air_pressure = str(weather.get_pressure()['press'])
        if 'deg' in weather.get_wind().keys():
            forecast_object.wind_deg = str(int(weather.get_wind()['deg']))

        if forecast_object.units == "metric":
            forecast_object.air_temperature = str(
                int(weather.get_temperature(unit='celsius')['temp']))
            forecast_object.wind_speed = str(int(
                weather.get_wind()['speed']))  # kmh

        if forecast_object.units == "aviation":
            forecast_object.air_temperature = str(
                int(weather.get_temperature(unit='celsius')['temp']))
            forecast_object.wind_speed = str(
                int(weather.get_wind()['speed'] * 1.94384))  # knots

        if forecast_object.units == "imperial":
            forecast_object.air_temperature = str(
                int(weather.get_temperature('fahrenheit')['temp']))
            forecast_object.wind_speed = str(
                int(weather.get_wind()['speed'] * 0.621))  # mph

        forecast_object.sunrise = datetime.fromtimestamp(
            int(weather.get_sunrise_time(timeformat='unix')))
        forecast_object.sunset = datetime.fromtimestamp(
            int(weather.get_sunset_time(timeformat='unix')))

        return forecast_object
Beispiel #5
0
def other_langage_deal(path):
    
    data_files = os.listdir(path)
    # 根据文件名获取新闻的语言信息
    langage_dict = {
        "CNN": "英语",
        "NHK": "日语",
        "YNA": "韩语"
    }
    # 媒体评分信息
    media_score = {
        "CNN": 75,
        "NHK": 75,
        "YNA": 75,
    }
    # 用于谷歌翻译的语言信息
    trans_dict = {
        "CNN": "en",
        "NHK": "ja",
        "YNA": "ko",       
    }

    crisisNewsFunc = CrisisNewsFunc() # 危机事件识别+评分
    id_list = []
    title_list = []
    time_list = []
    content_list = []
    url_list = []
    imgurl_list = []
    customer_list = []
    theme_label_list = []
    language_list = []
    reliability_list = []
    crisis_list = []

    title_zh_list = [] # 翻译后的中文title
    content_zh_list = [] # 翻译后的中文content

    for f in data_files: # 遍历数据文件    
        df = pd.read_csv(path + "/" + f)
        df['time'] = pd.to_datetime(df['time'])
        df = df.fillna('')  # 填充NA数据
        media_name = f.split(".")[0].split("_")[-1]
        langage_name = langage_dict[media_name]
        
        # 遍历读取处理        
        for i in tqdm(range(0, len(df))):
            row = df.iloc[i]
            id_list.append(uuid.uuid1())
            title_list.append(row['title']) 
            time_list.append(datetime.datetime.strftime(row['time'],'%Y-%m-%d %H:%M:%S')) # 格式化时间字符串
            content_list.append(row['content']) 
            url_list.append(row['url'])
            imgurl_list.append(row['img'])
            customer_list.append(row['source'])
            theme_label_list.append(row['theme'])
            
            language_list.append(langage_name)
            reliability_list.append(media_score[media_name] + random.randint(-20, 20)) # 新闻可靠性指数

            # 将多语言数据进行翻译存储
            title_zh = translate(row['title'])
            title_zh_list.append(title_zh)
            time.sleep(1) # 调用的翻译接口每秒只能访问一次
            content_zh = translate(row['content'])
            content_zh_list.append(content_zh)
            time.sleep(1) 
            
            # 危机指数计算
            # WJcrisis, WJWords = crisisNewsFunc.calcu_crisis(row['theme'], row['title'].lower(), row['content'].lower(), trans_dict[media_name])
            WJcrisis, WJWords = crisisNewsFunc.calcu_crisis_pro(row['theme'], title_zh)
            
            crisis_list.append(WJcrisis) # 新闻危机指数
    
    # 将结果存储到csv文件
    result = {
        "id": id_list,
        "title": title_list,
        "time": time_list,
        "url": url_list,
        "theme_label": theme_label_list,
        "customer": customer_list,
        "content": content_list,
        "imgurl": imgurl_list,
        "language": language_list,
        "reliability": reliability_list,
        "crisis": crisis_list,
        "title_zh": title_zh_list, # 翻译后的中文标题
        "content_zh": content_zh_list # 翻译后的正文
    }

    result_df = pd.DataFrame(result)
    # print(result_df.shape)
    result_df.to_csv("data/other_language_data.csv", header=True, index=False)
Beispiel #6
0
from Translator import translate

print(translate("a"))
# to install other py docx, go to cmd and type the pip command