notifier/services/core.py
Untone 315fe9fa49
All checks were successful
deploy / deploy (push) Successful in 1m7s
connectors-upgrade
2023-12-18 10:30:14 +03:00

37 lines
1.2 KiB
Python

from typing import Any, List
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) -> Any:
async with aiohttp.ClientSession() as session:
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, {})
return []
async def get_followed_shouts(author_id: int):
query_name = "load_shouts_followed"
operation = "GetFollowedShouts"
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 = {
"query": query,
"operationName": operation,
"variables": {"author_id": author_id, "limit": 1000, "offset": 0}, # FIXME: too big limit
}
return await _request_endpoint(query_name, body)