blob: 08373e07d829586fcdc5fe6b37d929ab06e731ca (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
|