diff --git a/app/search/services/spell_check.py b/app/search/services/spell_check.py new file mode 100644 index 0000000..120c0d2 --- /dev/null +++ b/app/search/services/spell_check.py @@ -0,0 +1,6 @@ +import requests as r + + +def spell_check(word: str) -> str: + res = r.get(f'https://speller.yandex.net/services/spellservice.json/checkText?text={word}') + return res.json()[0]['s'][0] diff --git a/app/search/services/translate.py b/app/search/services/translate.py new file mode 100644 index 0000000..8fa8f39 --- /dev/null +++ b/app/search/services/translate.py @@ -0,0 +1,13 @@ +import requests as r +from conf.settings.base import YANDEX_DICT_API_KEY +from itertools import chain +from typing import List + + +def translate_ru_en(word: str) -> List[str]: + res = r.get(f"https://dictionary.yandex.net/api/v1/dicservice.json/lookup?key={YANDEX_DICT_API_KEY}&lang=ru-en&text={word}") + return [i['text'] for i in chain(*[j['tr']for j in res.json()['def']])] + +def translate_en_ru(word: str) -> List[str]: + res = r.get(f"https://dictionary.yandex.net/api/v1/dicservice.json/lookup?key={YANDEX_DICT_API_KEY}&lang=en-ru&text={word}") + return [i['text'] for i in chain(*[j['tr']for j in res.json()['def']])]