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.1.tar.gz
(14.3 kB
view hashes)
Built Distribution
Close
Hashes for dynamicadaptor-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 03d034aa990ac87214e765ebcd277180eaeabeeabc7193a9476490f1850e7c21 |
|
MD5 | 9f17430d466f877abf280bebe595d824 |
|
BLAKE2b-256 | f99d6b2d1dafb0aa55c7419207742b25168e5b5357e941055853e932daca417e |