From 5911ea030f6daf46c01c77450d61efbe5085ddd7 Mon Sep 17 00:00:00 2001 From: Igor Chubin Date: Sun, 3 Jun 2018 18:46:19 +0000 Subject: [PATCH] initial support of foreign human languages in queries --- lib/get_answer.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/get_answer.py b/lib/get_answer.py index aebdf7b..0ee1889 100644 --- a/lib/get_answer.py +++ b/lib/get_answer.py @@ -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