Skip to content

Commit

Permalink
Move API URL to env
Browse files Browse the repository at this point in the history
  • Loading branch information
0is1 committed Feb 21, 2025
1 parent 6517a8a commit 3fbe988
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions server/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def env(variable, fallback_value=None):

SECRET_KEY = env("SECRET_KEY", "")
STT_FIN_API_KEY = env("STT_FIN_API_KEY", "")
STT_FIN_API_URL = env("STT_FIN_API_URL", "")

NO_TAKES = True

Expand Down
14 changes: 11 additions & 3 deletions server/stt/spellcheckers/stt_fin.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

logger = logging.getLogger(__name__)
OPT_API_KEY = "STT_FIN_API_KEY"
API_URL = "https://api.lingsoft.fi/lmc/{method}/"
OPT_API_URL_KEY = "STT_FIN_API_URL"


class SttFin(SpellcheckerBase):
Expand All @@ -34,10 +34,11 @@ class SttFin(SpellcheckerBase):
def __init__(self, app):
super().__init__(app)
self.api_key = self.config.get(OPT_API_KEY, os.environ.get(OPT_API_KEY))
self.api_url = self.config.get(OPT_API_URL_KEY, os.environ.get(OPT_API_URL_KEY))

def check(self, text, language=None):
try:
check_url = API_URL.format(method="proof")
check_url = self.api_url.format(method="proof")
data = {
"text": text,
"language": "fi",
Expand Down Expand Up @@ -114,7 +115,7 @@ def check(self, text, language=None):

def suggest(self, text, language=None):
try:
check_url = API_URL.format(method="proof")
check_url = self.api_url.format(method="proof")
data = {
"text": text,
"language": "fi",
Expand Down Expand Up @@ -152,6 +153,13 @@ def available(self):
)
)
return False
if not self.api_url:
logger.warning(
"API URL is not set for {label}, please set {opt} variable to use it".format(
label=self.label, opt=OPT_API_URL_KEY
)
)
return False
return True


Expand Down

0 comments on commit 3fbe988

Please sign in to comment.