No project description provided
Project description
DynamicAdaptor
用于将bilibili的grpc动态和web动态转换成特定的数据类型
原理说明
将grpc数据转换成json数据,之后使用pydantic进行信息摘要。 web端的json数据同理
下载安装
pip install dynamicadaptor
使用方法
from google.protobuf.json_format import MessageToDict
from dynamicadaptor.DynamicConversion import formate_message
from bilirpc.api import get_dy_detail
import asyncio
import httpx
# 如果数据是grpc返回的数据,则需要转换成json数据
async def sample1():
dynamic_grpc = await get_dy_detail("746530608345251842")
dynamic: dict = MessageToDict(dynamic_grpc[0])
dynamic_formate = formate_message("grpc", dynamic)
print(dynamic_formate)
asyncio.run(sample1())
# 如果是web返回的数据
async def sample2():
url = "https://api.bilibili.com/x/polymer/web-dynamic/v1/detail?timezone_offset=-480&id=746530608345251842"
headers = {
"Referer": "https://t.bilibili.com/746530608345251842"
}
result = httpx.get(url, headers=headers).json()
dynamic_formate = formate_message("web", result["data"]["item"])
print(dynamic_formate)
asyncio.run(sample2())
License
GPL
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
dynamicadaptor-0.1.6.tar.gz
(14.4 kB
view hashes)
Built Distribution
Close
Hashes for dynamicadaptor-0.1.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c3eda915194a85dea5c1ee1c7fd35951ed1d2edccba8f86e21750467561cbb2 |
|
MD5 | d58c40e17cf0db61a1e58b13af346cef |
|
BLAKE2b-256 | bd895928bb1e7eaaee15e99626d9ea89f110cf52c9f024776e2ebd64ea288ac3 |