added languages route

This commit is contained in:
ScuroNeko 2023-11-12 21:43:27 +03:00
parent 4f152233ca
commit fb5c53a6b7
6 changed files with 33 additions and 20 deletions

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
.idea/
.vscode/
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml

4
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,4 @@
{
"python.analysis.typeCheckingMode": "basic",
"python.analysis.autoImportCompletions": true
}

2
data

@ -1 +1 @@
Subproject commit df34257e5adc98acfa514eb6a91aae7dc4be4733
Subproject commit 50e2b26da886b97536db8c511394145e06b2c597

View File

@ -1,7 +1,7 @@
from fastapi import APIRouter
from subprocess import check_output
from src.constants import GAME_VERSION, SERVER_VERSION
from src.constants import GAME_VERSION, SERVER_VERSION, LANGUAGES
from src.errors import Response
@ -10,28 +10,33 @@ api = APIRouter(prefix='/api', tags=['Service'])
@api.get('/version')
async def get_versions():
commit_hash = git_revision_hash()
git_server = {
'commit': git_revision_short_hash(),
'commit_hash': commit_hash,
'branch': git_branch(),
'release': git_text(commit_hash)
}
git_server = git_info('.')
git_data = git_info('./data')
data_hash = git_revision_hash('./data')
git_data = {
'commit': git_revision_short_hash('./data'),
'commit_hash': data_hash,
'branch': git_branch('./data'),
'release': git_text(data_hash, './data')
}
reponse = {'server_version': SERVER_VERSION,
reponse = {'server_version': SERVER_VERSION,
'game_version': GAME_VERSION,
'git_server': git_server,
'git_data': git_data}
return Response(response=reponse)
@api.get('/languages')
async def get_languages():
return Response(response=LANGUAGES)
def git_info(path: str):
data_hash = git_revision_hash(path)
git = {
'commit': git_revision_short_hash(path),
'commit_hash': data_hash,
'branch': git_branch(path),
'release': git_text(data_hash, path)
}
return git
def git_revision_short_hash(cwd=None) -> str:
return check_out(['git', 'rev-parse', '--short', 'HEAD'], cwd)

View File

@ -10,15 +10,17 @@ geographies = APIRouter(prefix='/geographies', tags=['Geographies'])
@geographies.get('/')
async def get_geographies(query_field: str = 'names', query_languages: str = 'eng') -> Response:
query_langs = parse_query_langs(query_languages)
response: list[dict[str, list[str]]] = []
response: list = []
for query_lang in query_langs:
chars = load_index(query_lang, 'geographies')
response.append({query_lang: list(chars[query_field].keys())})
return Response[list[dict[str, list[str]]]](error=False, response=response)
return Response(error=False, response=response)
@geographies.get('/{query}', response_model_exclude_none=True)
async def get_geography(query: str, query_languages: str = 'eng', result_language: str = 'ru') -> Response[Geography]:
async def get_geography(
query: str, query_languages: str = 'eng', result_language: str = 'ru'
) -> Response[Geography]:
query_langs = parse_query_langs(query_languages)
result_lang = parse_result_lang(result_language)
filename = get_file_name(query, 'geographies', query_langs)

View File

@ -24,6 +24,7 @@ def load_file(folder: str, name: str) -> dict:
def get_file_name(query, category, langs) -> str:
for lang in langs:
index: dict[str, str] = load_index(lang, category)['names']
for key, value in index.items():
for k in key.lower().split(' '):
if k.startswith(query.lower()):