Commit 12bb0bd
Changed files (9)
src/asr/ali_asr.py
@@ -58,7 +58,7 @@ async def ali_asr(path: str | Path) -> dict:
"https://dashscope.aliyuncs.com/api/v1/services/audio/asr/transcription",
method="POST",
headers=headers,
- post_json=payload,
+ json_data=payload,
timeout=600,
check_keys=["output.task_id"],
)
@@ -84,7 +84,7 @@ async def query_ali_asr(task_id: str, api_key: str, query_times: int = 0) -> dic
f"https://dashscope.aliyuncs.com/api/v1/tasks/{task_id}",
method="POST",
headers=headers,
- post_json=payload,
+ json_data=payload,
check_keys=["output.task_status"],
)
if result.get("hx_error"):
src/asr/deepgram.py
@@ -30,7 +30,7 @@ async def deepgram_asr(path: str | Path) -> dict:
url,
method="POST",
headers=headers,
- post_content=await f.read(),
+ content_data=await f.read(),
params=params,
timeout=600,
check_keys=["results.channels.0.alternatives.0.words"],
src/asr/tecent_asr.py
@@ -86,7 +86,7 @@ async def tencent_single_asr(path: str | Path, engine: str, voice_format: str) -
"https://asr.tencentcloudapi.com",
method="POST",
headers=headers,
- post_content=payload.encode("utf-8"),
+ content_data=payload.encode("utf-8"),
timeout=60,
proxy=ASR.TENCENT_PROXY,
check_keys=["Response.WordList"],
@@ -127,7 +127,7 @@ async def tencent_flash_asr(path: str | Path, engine: str, voice_format: str) ->
url,
method="POST",
headers=headers,
- post_content=await f.read(),
+ content_data=await f.read(),
timeout=60,
proxy=ASR.TENCENT_PROXY,
check_kv={"code": 0},
@@ -166,7 +166,7 @@ async def tencent_async_asr(path: str | Path, engine: str) -> dict:
"https://asr.tencentcloudapi.com",
method="POST",
headers=headers,
- post_content=payload.encode("utf-8"),
+ content_data=payload.encode("utf-8"),
timeout=600,
proxy=ASR.TENCENT_PROXY,
check_keys=["Response.Data.TaskId"],
@@ -190,7 +190,7 @@ async def tencent_query_asr(task_id: int, file_name: str, query_times: int = 0)
"https://asr.tencentcloudapi.com",
method="POST",
headers=headers,
- post_content=payload.encode("utf-8"),
+ content_data=payload.encode("utf-8"),
timeout=600,
proxy=ASR.TENCENT_PROXY,
check_keys=["Response.Data.StatusStr"],
src/database/alist.py
@@ -19,7 +19,7 @@ async def list_alist() -> list[dict]:
return [{}]
api = DB.ALIST_SERVER.removesuffix("/") + "/api/fs/list"
logger.info(f"List Alist from: {api}")
- res = await hx_req(api, method="POST", post_json={"path": "/"}, check_kv={"code": 200})
+ res = await hx_req(api, method="POST", json_data={"path": "/"}, check_kv={"code": 200})
return glom(res, "data.content", default=[]) or []
@@ -72,7 +72,7 @@ async def delete_alist(fname: str, *, ensure_ascii: bool = True) -> None:
# Get JWT Token
payload = {"username": DB.ALIST_USERNAME, "password": DB.ALIST_PASSWORD}
auth_api = DB.ALIST_SERVER.removesuffix("/") + "/api/auth/login"
- res = await hx_req(auth_api, method="POST", post_json=payload, check_keys=["data.token"])
+ res = await hx_req(auth_api, method="POST", json_data=payload, check_keys=["data.token"])
token = res["data"]["token"]
# Delete
@@ -84,4 +84,4 @@ async def delete_alist(fname: str, *, ensure_ascii: bool = True) -> None:
else:
payload = {"names": [fname]}
logger.info(f"Delete {fname} from: {api}")
- res = await hx_req(api, method="POST", headers=headers, post_json=payload, check_kv={"code": 200})
+ res = await hx_req(api, method="POST", headers=headers, json_data=payload, check_kv={"code": 200})
src/database/d1.py
@@ -29,7 +29,7 @@ async def create_d1_database(
return database_id
if primary_location_hint:
payload |= {"primary_location_hint": primary_location_hint}
- resp = await hx_req(api, method="POST", post_json=payload, headers=headers, check_kv={"success": True}, proxy=PROXY.D1, max_retry=0, silent=silent)
+ resp = await hx_req(api, method="POST", json_data=payload, headers=headers, check_kv={"success": True}, proxy=PROXY.D1, max_retry=0, silent=silent)
return glom(resp, "result.uuid", default="")
@@ -83,4 +83,4 @@ async def query_d1(
payload |= {"params": params}
if not silent:
logger.trace(f"Query CF-D1: {payload}")
- return await hx_req(api, "POST", post_json=payload, headers=headers, check_kv={"success": True}, proxy=PROXY.D1, max_retry=0, silent=silent)
+ return await hx_req(api, "POST", json_data=payload, headers=headers, check_kv={"success": True}, proxy=PROXY.D1, max_retry=0, silent=silent)
src/database/turso.py
@@ -29,7 +29,7 @@ async def turso_db_url(
return "https://" + next(x["hostname"] for x in resp["databases"] if x["Name"] == name) + "/v2/pipeline"
# not exists, create it
- resp = await hx_req(api, method="POST", post_json=payload, headers=headers, check_kv={"database.Name": name}, check_keys=["database.Hostname"], proxy=PROXY.TURSO, silent=silent)
+ resp = await hx_req(api, method="POST", json_data=payload, headers=headers, check_kv={"database.Name": name}, check_keys=["database.Hostname"], proxy=PROXY.TURSO, silent=silent)
return "https://" + resp["database"]["Hostname"] + "/v2/pipeline"
@@ -87,4 +87,4 @@ async def turso_exec(
statements.append({"type": "close"})
if not silent:
logger.trace(f"Turso Exec: {statements}")
- return await hx_req(db_url, "POST", post_json={"requests": statements}, headers=headers, check_keys=["results"], proxy=PROXY.TURSO, max_retry=retry, silent=silent, timeout=600)
+ return await hx_req(db_url, "POST", json_data={"requests": statements}, headers=headers, check_keys=["results"], proxy=PROXY.TURSO, max_retry=retry, silent=silent, timeout=600)
src/price/tradingview.py
@@ -86,7 +86,7 @@ async def get_tradingview_price(symbol: str, interval: str | None = None, **kwar
"override": {"showStudyLastValue": False},
}
logger.trace(params)
- resp = await hx_req("https://api.chart-img.com/v2/tradingview/advanced-chart/storage", "POST", max_retry=0, headers={"x-api-key": TOKEN.CHART_IMG}, post_json=params, check_keys=["url"])
+ resp = await hx_req("https://api.chart-img.com/v2/tradingview/advanced-chart/storage", "POST", max_retry=0, headers={"x-api-key": TOKEN.CHART_IMG}, json_data=params, check_keys=["url"])
if error := resp.get("hx_error"):
await modify_progress(text=f"❌Failed to fetch TradingView chart for {query_symbol} @{interval} in {market.capitalize()}\n{error}", force_update=True, **kwargs)
return {}
src/networking.py
@@ -40,8 +40,8 @@ async def hx_req(
cookies: dict | None = None,
params: dict | None = None,
data: RequestData | None = None,
- post_json: dict | None = None,
- post_content: RequestContent | None = None,
+ json_data: dict | None = None,
+ content_data: RequestContent | None = None,
files: RequestFiles | None = None,
proxy: str | None = None,
follow_redirects: bool = True,
@@ -64,8 +64,8 @@ async def hx_req(
cookies (dict, optional): The cookies to use for the request.
params (dict, optional): The parameters to use for the request.
data (dict, optional): The data to POST or PUT.
- post_json (dict, optional): The JSON data to POST.
- post_content (dict, optional): The form data to POST.
+ json_data (dict, optional): The JSON data to POST or PUT.
+ content_data (dict, optional): The form data to POST or PUT.
proxy (str, optional): The proxy to use for the request.
follow_redirects (bool, optional): Whether to follow redirects.
check_keys (list[str], optional): The keys to check in the response.
@@ -100,9 +100,9 @@ async def hx_req(
if method == "GET":
response = await client.get(url, cookies=cookies, headers=headers, params=params)
elif method == "POST":
- response = await client.post(url, cookies=cookies, headers=headers, data=data, json=post_json, files=files, content=post_content, params=params)
+ response = await client.post(url, cookies=cookies, headers=headers, data=data, json=json_data, files=files, content=content_data, params=params)
else:
- response = await client.put(url, cookies=cookies, headers=headers, data=data, files=files, params=params)
+ response = await client.put(url, cookies=cookies, headers=headers, data=data, json=json_data, content=content_data, files=files, params=params)
response.raise_for_status()
if rformat == "content":
return {"content": response.content}
@@ -121,7 +121,7 @@ async def hx_req(
elif "data" in locals():
error += f"\n{data}"
logger.error(error)
- return await hx_req(url, method, headers=headers, cookies=cookies, params=params, data=data, post_json=post_json, proxy=proxy, follow_redirects=follow_redirects, check_keys=check_keys, check_kv=check_kv, timeout=timeout, retry=retry + 1, max_retry=max_retry, silent=silent, rformat=rformat, last_error=error) # fmt: off
+ return await hx_req(url, method, headers=headers, cookies=cookies, params=params, data=data, json_data=json_data, proxy=proxy, follow_redirects=follow_redirects, check_keys=check_keys, check_kv=check_kv, timeout=timeout, retry=retry + 1, max_retry=max_retry, silent=silent, rformat=rformat, last_error=error) # fmt: off
async def download_file(