Улучшение обработки запросов к VNDB API и изменение структуры полей в ответах
This commit is contained in:
12
bot.py
12
bot.py
@@ -182,8 +182,8 @@ Staff: {stats.get('staff', 0)}
|
|||||||
)
|
)
|
||||||
|
|
||||||
results = await vndb_client.query_vn(
|
results = await vndb_client.query_vn(
|
||||||
filters=["search", "=", query],
|
filters=["search", "=", query], # ✔️ без вложенности
|
||||||
fields=["title", "id", "image{url}"],
|
fields=["id", "title", "image{url}"],
|
||||||
results=10
|
results=10
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -228,8 +228,8 @@ Staff: {stats.get('staff', 0)}
|
|||||||
return ConversationHandler.END
|
return ConversationHandler.END
|
||||||
|
|
||||||
results = await vndb_client.query_character(
|
results = await vndb_client.query_character(
|
||||||
filters=["search", "=", query],
|
filters=["search", "=", query], # ✔️ важно
|
||||||
fields=["name", "id", "image{url}"],
|
fields=["id", "name", "image{url}"],
|
||||||
results=10
|
results=10
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -255,8 +255,8 @@ Staff: {stats.get('staff', 0)}
|
|||||||
query = " ".join(context.args)
|
query = " ".join(context.args)
|
||||||
|
|
||||||
results = await vndb_client.query_release(
|
results = await vndb_client.query_release(
|
||||||
filters=["search", "=", query],
|
filters=["search", "=", query], # ✔️ важно
|
||||||
fields=["title", "id"],
|
fields=["id", "title"],
|
||||||
results=10
|
results=10
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -55,30 +55,20 @@ class VndbClient:
|
|||||||
method: str = "GET",
|
method: str = "GET",
|
||||||
data: Optional[Dict[str, Any]] = None,
|
data: Optional[Dict[str, Any]] = None,
|
||||||
) -> Dict[str, Any]:
|
) -> Dict[str, Any]:
|
||||||
"""
|
|
||||||
Make HTTP request to VNDB API
|
|
||||||
|
|
||||||
Args:
|
|
||||||
endpoint: API endpoint
|
|
||||||
method: HTTP method (GET, POST, PATCH, DELETE)
|
|
||||||
data: Request body data
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
Response JSON
|
|
||||||
|
|
||||||
Raises:
|
|
||||||
httpx.HTTPError: On HTTP errors
|
|
||||||
json.JSONDecodeError: On invalid JSON response
|
|
||||||
"""
|
|
||||||
url = f"{self.base_url}{endpoint}"
|
url = f"{self.base_url}{endpoint}"
|
||||||
|
|
||||||
async with httpx.AsyncClient(timeout=10) as client:
|
async with httpx.AsyncClient(timeout=15) as client:
|
||||||
response = await client.request(
|
response = await client.request(
|
||||||
method,
|
method,
|
||||||
url,
|
url,
|
||||||
headers=self.headers,
|
headers=self.headers,
|
||||||
content=json.dumps(data) if data else None,
|
json=data if data else None, # 🔥 ВАЖНО: json= вместо content=
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if response.status_code >= 400:
|
||||||
|
print("VNDB ERROR:", response.status_code, response.text)
|
||||||
|
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
return response.json()
|
return response.json()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user