core-api-fix
All checks were successful
deploy / deploy (push) Successful in 1m17s

This commit is contained in:
Untone 2023-11-06 19:25:28 +03:00
parent aefb94de66
commit 1fe3d774bf

View File

@ -6,17 +6,19 @@ from settings import API_BASE
from validators.member import ChatMember
headers = {"Content-Type": "application/json"}
INTERNAL_AUTH_SERVER = 'v2.' in API_BASE
async def get_author(author_id):
query_name = "GetAuthor" if INTERNAL_AUTH_SERVER else "GetAuthorById"
query_type = "query"
operation = "GetAuthorById"
query_fields = "id slug userpic name lastSeen" if INTERNAL_AUTH_SERVER else "id slug userpic name last_seen"
headers = {"Content-Type": "application/json"} # "Bearer " + removed
gql = {
"query": """query GetAuthorById($author_id: Int!) {
getAuthorById(author_id: $author_id) {
id slug userpic name lastSeen
}
}""",
"operation": "GetAuthorById",
"variables": {"author_id": int(author_id)},
"query": query_type + " " + operation + " { " + query_name + " { " + query_fields + " } " + " }",
"operationName": operation,
"variables": None,
}
async with AsyncClient() as client:
try:
@ -30,10 +32,10 @@ async def get_author(author_id):
r = response.json()
a = r.get("data", {}).get("getAuthorById")
if a:
last_seen = a.get("lastSeen")
dt = datetime.strptime(last_seen, "%Y-%m-%dT%H:%M:%S.%f")
ts_value = a.get("lastSeen", a.get("last_seen"))
dt = datetime.strptime(ts_value, "%Y-%m-%dT%H:%M:%S.%f")
timestamp = int(dt.timestamp())
a["lastSeen"] = timestamp
a["last_seen"] = timestamp
author: ChatMember = a
return author