Этот коммит содержится в:
viginum-datalab 2025-03-05 16:43:34 +01:00
родитель b590d46525
Коммит cacca2ab9f
4 изменённых файлов: 18 добавлений и 15 удалений

Просмотреть файл

@ -116,7 +116,7 @@ class AccountsPool:
logger.warning("No usernames provided")
return
qs = f"""DELETE FROM accounts WHERE username IN ({','.join([f'"{x}"' for x in usernames])})"""
qs = f"""DELETE FROM accounts WHERE username IN ({",".join([f'"{x}"' for x in usernames])})"""
await execute(self._db_file, qs)
async def delete_inactive(self):
@ -201,7 +201,7 @@ class AccountsPool:
headers = json_object(),
cookies = json_object(),
user_agent = "{UserAgent().safari}"
WHERE username IN ({','.join([f'"{x}"' for x in usernames])})
WHERE username IN ({",".join([f'"{x}"' for x in usernames])})
"""
await execute(self._db_file, qs)

Просмотреть файл

@ -1,9 +1,9 @@
from contextlib import aclosing
from httpx import Response
from json import loads
import zstd
from httpx import Response
from typing_extensions import deprecated
from zstd import decompress
from .accounts_pool import AccountsPool
from .logger import set_log_level
@ -129,7 +129,7 @@ class API:
return
encoding: str | None = rep.headers.get("content-encoding")
obj = loads(decompress(rep.content)) if encoding == "zstd" else rep.json()
obj = loads(zstd.decompress(rep.content)) if encoding == "zstd" else rep.json()
els = get_by_path(obj, "entries") or []
els = [
x

Просмотреть файл

@ -135,7 +135,7 @@ class User(JSONTrait):
return User(
id=int(obj["id_str"]),
id_str=obj["id_str"],
url=f'https://x.com/{obj["screen_name"]}',
url=f"https://x.com/{obj['screen_name']}",
username=obj["screen_name"],
displayname=obj["name"],
rawDescription=obj["description"],
@ -217,7 +217,7 @@ class Tweet(JSONTrait):
rt_obj = get_or(res, f"tweets.{_first(obj, rt_id_path)}")
qt_obj = get_or(res, f"tweets.{_first(obj, qt_id_path)}")
url = f'https://x.com/{tw_usr.username}/status/{obj["id_str"]}'
url = f"https://x.com/{tw_usr.username}/status/{obj['id_str']}"
doc = Tweet(
id=int(obj["id_str"]),
id_str=obj["id_str"],
@ -507,8 +507,8 @@ def _parse_card(obj: dict, url: str):
options = []
for x in range(20):
label = _parse_card_get_str(val, f"choice{x+1}_label")
votes = _parse_card_get_str(val, f"choice{x+1}_count")
label = _parse_card_get_str(val, f"choice{x + 1}_label")
votes = _parse_card_get_str(val, f"choice{x + 1}_count")
if label is None or votes is None:
break

Просмотреть файл

@ -1,9 +1,9 @@
from json import JSONDecodeError, dumps, loads
import os
from json import JSONDecodeError, dumps, loads
from typing import Any
from zstd import decompress
import httpx
import zstd
from httpx import AsyncClient, Response
from .accounts_pool import Account, AccountsPool
@ -58,7 +58,7 @@ def dump_rep(rep: Response):
try:
encoding: str | None = rep.headers.get("content-encoding")
obj = loads(decompress(rep.content)) if encoding == "zstd" else rep.json()
obj = loads(zstd.decompress(rep.content)) if encoding == "zstd" else rep.json()
msg.append(dumps(obj, indent=2))
except JSONDecodeError:
msg.append(rep.text)
@ -124,7 +124,7 @@ class QueueClient:
try:
encoding: str | None = rep.headers.get("content-encoding")
res = loads(decompress(rep.content)) if encoding == "zstd" else rep.json()
res = loads(zstd.decompress(rep.content)) if encoding == "zstd" else rep.json()
except JSONDecodeError:
res: Any = {"_raw": rep.text}
@ -134,7 +134,7 @@ class QueueClient:
err_msg = "OK"
if "errors" in res:
err_msg = set([f'({x.get("code", -1)}) {x["message"]}' for x in res["errors"]])
err_msg = set([f"({x.get('code', -1)}) {x['message']}" for x in res["errors"]])
err_msg = "; ".join(list(err_msg))
log_msg = f"{rep.status_code:3d} - {req_id(rep)} - {err_msg}"
@ -235,6 +235,9 @@ class QueueClient:
connection_retry += 1
if connection_retry >= 3:
raise e
except zstd.Error as e:
logger.error(f"Failed to decompress ZSTD: {e}")
return
except Exception as e:
unknown_retry += 1
if unknown_retry >= 3: