change translate

This commit is contained in:
ilia 2022-10-22 17:31:40 +03:00
parent c9ad0a1e7a
commit eecc1976f9
4 changed files with 12 additions and 2 deletions

View File

@ -1,3 +1,4 @@
DJANGO_DEBUG=yes DJANGO_DEBUG=yes
DATABASE_URL=postgres://postgres:debug@127.0.0.1:5432/tenderhack DATABASE_URL=postgres://postgres:debug@127.0.0.1:5432/tenderhack
CELERY_BROKER_URL=redis://localhost:6379/0 CELERY_BROKER_URL=redis://localhost:6379/0
YANDEX_DICT=<your_yandex_dict_api_key>

View File

@ -1,4 +1,5 @@
from pathlib import Path from pathlib import Path
import os
import environ import environ
@ -38,6 +39,8 @@ LOCALE_PATHS = [str(APPS_DIR / "locale")]
# https://docs.djangoproject.com/en/dev/ref/settings/#databases # https://docs.djangoproject.com/en/dev/ref/settings/#databases
DATABASES = {"default": env.db("DATABASE_URL")} DATABASES = {"default": env.db("DATABASE_URL")}
DATABASES["default"]["ATOMIC_REQUESTS"] = True DATABASES["default"]["ATOMIC_REQUESTS"] = True
YANDEX_DICT_API_KEY = env.str('YANDEX_DICT')
# https://docs.djangoproject.com/en/stable/ref/settings/#std:setting-DEFAULT_AUTO_FIELD # https://docs.djangoproject.com/en/stable/ref/settings/#std:setting-DEFAULT_AUTO_FIELD
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

View File

@ -1,6 +1,10 @@
import requests as r import requests as r
from spellchecker import SpellChecker
speller = SpellChecker(language='ru')
def spell_check(word: str) -> str: def spell_check(word: str) -> str:
res = r.get(f'https://speller.yandex.net/services/spellservice.json/checkText?text={word}') res = speller.correction(word)
return res.json()[0]['s'][0] if not len(res):
return word
return res

View File

@ -10,3 +10,5 @@ redis==4.3.4
psycopg2-binary==2.9.4 psycopg2-binary==2.9.4
celery==5.2.7 celery==5.2.7
pyspellchecker==0.7.0