From 1fe3d774bf4c2b0007399fa98e7500d8f42c7b61 Mon Sep 17 00:00:00 2001 From: Untone Date: Mon, 6 Nov 2023 19:25:28 +0300 Subject: [PATCH] core-api-fix --- services/core.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/services/core.py b/services/core.py index bf4a504..bb7d091 100644 --- a/services/core.py +++ b/services/core.py @@ -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