This commit is contained in:
@@ -5,34 +5,26 @@ import aiohttp
|
||||
from settings import API_BASE
|
||||
|
||||
headers = {"Content-Type": "application/json"}
|
||||
api_base = API_BASE or "https://core.discours.io"
|
||||
|
||||
|
||||
async def _request_endpoint(query_name, body):
|
||||
async def _request_endpoint(query_name, body) -> Any:
|
||||
async with aiohttp.ClientSession() as session:
|
||||
try:
|
||||
async with session.post(API_BASE, headers=headers, json=body) as response:
|
||||
print(f"[services.core] {query_name}: [{response.status}] {len(await response.text())} bytes")
|
||||
if response.status != 200:
|
||||
return []
|
||||
async with session.post(API_BASE, headers=headers, json=body) as response:
|
||||
print(f"[services.core] {query_name} response: <{response.status}> {await response.text()}")
|
||||
if response.status == 200:
|
||||
r = await response.json()
|
||||
if r:
|
||||
return r.get("data", {}).get(query_name, {})
|
||||
else:
|
||||
raise Exception("json response error")
|
||||
except Exception:
|
||||
import traceback
|
||||
|
||||
traceback.print_exc()
|
||||
return []
|
||||
|
||||
|
||||
async def get_followed_shouts(author_id: int):
|
||||
query_name = "load_shouts_followed"
|
||||
query_type = "query"
|
||||
operation = "GetFollowedShouts"
|
||||
query_fields = "id slug title"
|
||||
|
||||
query = f"""{query_type} {operation}($author_id: Int!, limit: Int, offset: Int) {{
|
||||
{query_name}(author_id: $author_id, limit: $limit, offset: $offset) {{ {query_fields} }}
|
||||
query = f"""query {operation}($author_id: Int!, limit: Int, offset: Int) {{
|
||||
{query_name}(author_id: $author_id, limit: $limit, offset: $offset) {{ id slug title }}
|
||||
}}"""
|
||||
|
||||
body = {
|
||||
|
Reference in New Issue
Block a user