1
1
mirror of https://github.com/chubin/cheat.sh.git synced 2024-11-24 03:56:55 +03:00

initial support of foreign human languages in queries

This commit is contained in:
Igor Chubin 2018-06-03 18:46:19 +00:00
parent 5ed0e75424
commit 5911ea030f

View File

@ -19,6 +19,7 @@ import os
import re
import redis
from fuzzywuzzy import process, fuzz
from langdetect import detect
import beautifier
from globals import MYDIR, PATH_TLDR_PAGES, PATH_CHEAT_PAGES, PATH_CHEAT_SHEETS, COLOR_STYLES
@ -250,7 +251,14 @@ def _get_answer_for_question(topic):
"""
topic = " ".join(topic.replace('+', ' ').strip().split())
cmd = ["/home/igor/cheat.sh/bin/get-answer-for-question", topic]
lang = detect(topic)
if lang != 'en':
topic = ['--human-language', lang, topic]
else:
topic = [topic]
cmd = ["/home/igor/cheat.sh/bin/get-answer-for-question"] + topic
proc = Popen(cmd, stdout=PIPE, stderr=PIPE)
answer = proc.communicate()[0].decode('utf-8')
return answer