From ee7123f38219c99f37c21e92b8cb96e014748b16 Mon Sep 17 00:00:00 2001 From: Stas Medvedev Date: Tue, 11 Jun 2024 01:24:14 +0300 Subject: utils.py, logging.py, log_config.json --- app/utils.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 app/utils.py (limited to 'app/utils.py') diff --git a/app/utils.py b/app/utils.py new file mode 100644 index 0000000..08373e0 --- /dev/null +++ b/app/utils.py @@ -0,0 +1,31 @@ +from pathlib import Path +from fastapi import Request +import httpx + + +def get_avatar_urls(): + path = Path('./static') / 'avatars' + if not path.exists(): + path.mkdir() + + return sorted([ + str(jpg_avatar) + for jpg_avatar + in path.glob('*.jpg') + ]) + + +def get_client_host(request: Request): + return request.client.host + + +async def get_client_geo(client_host: str): + async with httpx.AsyncClient() as client: + response = await client.get( + # использование https платная опция сервиса, инфо тут https://members.ip-api.com/ + url='http://ip-api.com/json/{}'.format(client_host), + params={"lang": "ru"} + ) + data = response.json() + return data + -- cgit v1.2.3