Skip to content

Commit

Permalink
Merge pull request #248 from lumina37/develop
Browse files Browse the repository at this point in the history
Update 4.5.0
  • Loading branch information
lumina37 authored Dec 19, 2024
2 parents 65253e8 + 48b9565 commit 92fe0f1
Show file tree
Hide file tree
Showing 39 changed files with 1,094 additions and 602 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI-beta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
python-version: ${{ env.PYTHON_VERSION }}

- name: Setup UV
uses: astral-sh/setup-uv@v3
uses: astral-sh/setup-uv@v4

- name: Install dependencies
run: uv sync
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
ref: develop

- name: Setup UV
uses: astral-sh/setup-uv@v3
uses: astral-sh/setup-uv@v4

- name: Install dependencies
run: uv sync -p ${{ matrix.python-version }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/Pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
ref: develop

- name: Setup UV
uses: astral-sh/setup-uv@v3
uses: astral-sh/setup-uv@v4

- name: Install dependencies
run: uv sync --only-dev
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/Publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- uses: actions/checkout@v4

- name: Build wheels
uses: pypa/cibuildwheel@v2.21.3
uses: pypa/cibuildwheel@v2.22.0

- uses: actions/upload-artifact@v4
with:
Expand Down
1 change: 0 additions & 1 deletion aiotieba/api/_classdef/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,4 @@
TypeFragTiebaPlus,
)
from .user import UserInfo
from .vimage import VirtualImage
from .vote import VoteInfo
3 changes: 0 additions & 3 deletions aiotieba/api/_classdef/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import dataclasses as dcs

from ...enums import Gender, PrivLike, PrivReply
from .vimage import VirtualImage


@dcs.dataclass
Expand All @@ -30,7 +29,6 @@ class UserInfo:
sign (str): 个性签名
ip (str): ip归属地
icons (list[str]): 印记信息
vimage (VirtualImage_pf): 虚拟形象信息
is_vip (bool): 是否超级会员
is_god (bool): 是否大神
Expand Down Expand Up @@ -61,7 +59,6 @@ class UserInfo:
sign: str = ""
ip: str = ''
icons: list[str] = dcs.field(default_factory=list)
vimage: VirtualImage = dcs.field(default_factory=VirtualImage)

is_vip: bool = False
is_god: bool = False
Expand Down
8 changes: 0 additions & 8 deletions aiotieba/api/_protobuf/User.proto
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,6 @@ message User {
int32 is_default_avatar = 106;
string tieba_uid = 120;
string ip_address = 127;
message VirtualImageInfo {
int32 isset_virtual_image = 1;
message StateInfo {
string text = 2;
}
StateInfo personal_state = 9;
}
VirtualImageInfo virtual_image_info = 136;
message UserGrowth {
uint32 level_id = 1;
}
Expand Down
36 changes: 16 additions & 20 deletions aiotieba/api/_protobuf/User_pb2.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(
b'\n\nUser.proto"\x92\n\n\x04User\x12\n\n\x02id\x18\x02 \x01(\x03\x12\x0c\n\x04name\x18\x03 \x01(\t\x12\x11\n\tname_show\x18\x04 \x01(\t\x12\x10\n\x08portrait\x18\x05 \x01(\t\x12\x1c\n\x08iconinfo\x18\x11 \x03(\x0b\x32\n.User.Icon\x12\x13\n\x0bis_coreuser\x18\x14 \x01(\x05\x12\x10\n\x08level_id\x18\x17 \x01(\x05\x12\x0f\n\x07is_bawu\x18\x19 \x01(\x05\x12\x11\n\tbawu_type\x18\x1a \x01(\t\x12\r\n\x05\x42\x44USS\x18\x1d \x01(\t\x12\x10\n\x08\x66\x61ns_num\x18\x1e \x01(\x05\x12\x13\n\x0b\x63oncern_num\x18\x1f \x01(\x05\x12\x0b\n\x03sex\x18 \x01(\x05\x12\x13\n\x0bmy_like_num\x18! \x01(\x05\x12\r\n\x05intro\x18" \x01(\t\x12\x10\n\x08post_num\x18% \x01(\x05\x12\x0e\n\x06tb_age\x18& \x01(\t\x12\x0e\n\x06gender\x18* \x01(\x05\x12!\n\tpriv_sets\x18- \x01(\x0b\x32\x0e.User.PrivSets\x12\x11\n\tis_friend\x18. \x01(\x05\x12&\n\tlikeForum\x18/ \x03(\x0b\x32\x13.User.LikeForumInfo\x12\x13\n\x0bis_guanfang\x18\x34 \x01(\x05\x12"\n\x07vipInfo\x18= \x01(\x0b\x32\x11.User.UserVipInfo\x12\'\n\x0enew_tshow_icon\x18\x41 \x03(\x0b\x32\x0f.User.TshowInfo\x12\x0f\n\x07is_fans\x18[ \x01(\x05\x12&\n\x0cnew_god_data\x18\x65 \x01(\x0b\x32\x10.User.NewGodInfo\x12\x19\n\x11is_default_avatar\x18j \x01(\x05\x12\x11\n\ttieba_uid\x18x \x01(\t\x12\x12\n\nip_address\x18\x7f \x01(\t\x12\x33\n\x12virtual_image_info\x18\x88\x01 \x01(\x0b\x32\x16.User.VirtualImageInfo\x12&\n\x0buser_growth\x18\x89\x01 \x01(\x0b\x32\x10.User.UserGrowth\x1a\x14\n\x04Icon\x12\x0c\n\x04name\x18\x01 \x01(\t\x1a\xab\x01\n\x08PrivSets\x12\x10\n\x08location\x18\x01 \x01(\x05\x12\x0c\n\x04like\x18\x02 \x01(\x05\x12\r\n\x05group\x18\x03 \x01(\x05\x12\x0c\n\x04post\x18\x04 \x01(\x05\x12\x0e\n\x06\x66riend\x18\x05 \x01(\x05\x12\x0c\n\x04live\x18\x06 \x01(\x05\x12\r\n\x05reply\x18\x07 \x01(\x05\x12\x19\n\x11\x62\x61zhu_show_inside\x18\x08 \x01(\x05\x12\x1a\n\x12\x62\x61zhu_show_outside\x18\t \x01(\x05\x1a\x35\n\rLikeForumInfo\x12\x12\n\nforum_name\x18\x01 \x01(\t\x12\x10\n\x08\x66orum_id\x18\x02 \x01(\x04\x1a\x30\n\x0bUserVipInfo\x12\x10\n\x08v_status\x18\x01 \x01(\r\x12\x0f\n\x07v_level\x18\x05 \x01(\r\x1a\x19\n\tTshowInfo\x12\x0c\n\x04name\x18\x02 \x01(\t\x1a\x42\n\nNewGodInfo\x12\x0e\n\x06status\x18\x01 \x01(\x05\x12\x10\n\x08\x66ield_id\x18\x02 \x01(\r\x12\x12\n\nfield_name\x18\x03 \x01(\t\x1a\x84\x01\n\x10VirtualImageInfo\x12\x1b\n\x13isset_virtual_image\x18\x01 \x01(\x05\x12\x38\n\x0epersonal_state\x18\t \x01(\x0b\x32 .User.VirtualImageInfo.StateInfo\x1a\x19\n\tStateInfo\x12\x0c\n\x04text\x18\x02 \x01(\t\x1a\x1e\n\nUserGrowth\x12\x10\n\x08level_id\x18\x01 \x01(\rb\x06proto3'
b'\n\nUser.proto"\xd6\x08\n\x04User\x12\n\n\x02id\x18\x02 \x01(\x03\x12\x0c\n\x04name\x18\x03 \x01(\t\x12\x11\n\tname_show\x18\x04 \x01(\t\x12\x10\n\x08portrait\x18\x05 \x01(\t\x12\x1c\n\x08iconinfo\x18\x11 \x03(\x0b\x32\n.User.Icon\x12\x13\n\x0bis_coreuser\x18\x14 \x01(\x05\x12\x10\n\x08level_id\x18\x17 \x01(\x05\x12\x0f\n\x07is_bawu\x18\x19 \x01(\x05\x12\x11\n\tbawu_type\x18\x1a \x01(\t\x12\r\n\x05\x42\x44USS\x18\x1d \x01(\t\x12\x10\n\x08\x66\x61ns_num\x18\x1e \x01(\x05\x12\x13\n\x0b\x63oncern_num\x18\x1f \x01(\x05\x12\x0b\n\x03sex\x18 \x01(\x05\x12\x13\n\x0bmy_like_num\x18! \x01(\x05\x12\r\n\x05intro\x18" \x01(\t\x12\x10\n\x08post_num\x18% \x01(\x05\x12\x0e\n\x06tb_age\x18& \x01(\t\x12\x0e\n\x06gender\x18* \x01(\x05\x12!\n\tpriv_sets\x18- \x01(\x0b\x32\x0e.User.PrivSets\x12\x11\n\tis_friend\x18. \x01(\x05\x12&\n\tlikeForum\x18/ \x03(\x0b\x32\x13.User.LikeForumInfo\x12\x13\n\x0bis_guanfang\x18\x34 \x01(\x05\x12"\n\x07vipInfo\x18= \x01(\x0b\x32\x11.User.UserVipInfo\x12\'\n\x0enew_tshow_icon\x18\x41 \x03(\x0b\x32\x0f.User.TshowInfo\x12\x0f\n\x07is_fans\x18[ \x01(\x05\x12&\n\x0cnew_god_data\x18\x65 \x01(\x0b\x32\x10.User.NewGodInfo\x12\x19\n\x11is_default_avatar\x18j \x01(\x05\x12\x11\n\ttieba_uid\x18x \x01(\t\x12\x12\n\nip_address\x18\x7f \x01(\t\x12&\n\x0buser_growth\x18\x89\x01 \x01(\x0b\x32\x10.User.UserGrowth\x1a\x14\n\x04Icon\x12\x0c\n\x04name\x18\x01 \x01(\t\x1a\xab\x01\n\x08PrivSets\x12\x10\n\x08location\x18\x01 \x01(\x05\x12\x0c\n\x04like\x18\x02 \x01(\x05\x12\r\n\x05group\x18\x03 \x01(\x05\x12\x0c\n\x04post\x18\x04 \x01(\x05\x12\x0e\n\x06\x66riend\x18\x05 \x01(\x05\x12\x0c\n\x04live\x18\x06 \x01(\x05\x12\r\n\x05reply\x18\x07 \x01(\x05\x12\x19\n\x11\x62\x61zhu_show_inside\x18\x08 \x01(\x05\x12\x1a\n\x12\x62\x61zhu_show_outside\x18\t \x01(\x05\x1a\x35\n\rLikeForumInfo\x12\x12\n\nforum_name\x18\x01 \x01(\t\x12\x10\n\x08\x66orum_id\x18\x02 \x01(\x04\x1a\x30\n\x0bUserVipInfo\x12\x10\n\x08v_status\x18\x01 \x01(\r\x12\x0f\n\x07v_level\x18\x05 \x01(\r\x1a\x19\n\tTshowInfo\x12\x0c\n\x04name\x18\x02 \x01(\t\x1a\x42\n\nNewGodInfo\x12\x0e\n\x06status\x18\x01 \x01(\x05\x12\x10\n\x08\x66ield_id\x18\x02 \x01(\r\x12\x12\n\nfield_name\x18\x03 \x01(\t\x1a\x1e\n\nUserGrowth\x12\x10\n\x08level_id\x18\x01 \x01(\rb\x06proto3'
)

_globals = globals()
Expand All @@ -18,22 +18,18 @@
if not _descriptor._USE_C_DESCRIPTORS:
DESCRIPTOR._loaded_options = None
_globals['_USER']._serialized_start = 15
_globals['_USER']._serialized_end = 1313
_globals['_USER_ICON']._serialized_start = 752
_globals['_USER_ICON']._serialized_end = 772
_globals['_USER_PRIVSETS']._serialized_start = 775
_globals['_USER_PRIVSETS']._serialized_end = 946
_globals['_USER_LIKEFORUMINFO']._serialized_start = 948
_globals['_USER_LIKEFORUMINFO']._serialized_end = 1001
_globals['_USER_USERVIPINFO']._serialized_start = 1003
_globals['_USER_USERVIPINFO']._serialized_end = 1051
_globals['_USER_TSHOWINFO']._serialized_start = 1053
_globals['_USER_TSHOWINFO']._serialized_end = 1078
_globals['_USER_NEWGODINFO']._serialized_start = 1080
_globals['_USER_NEWGODINFO']._serialized_end = 1146
_globals['_USER_VIRTUALIMAGEINFO']._serialized_start = 1149
_globals['_USER_VIRTUALIMAGEINFO']._serialized_end = 1281
_globals['_USER_VIRTUALIMAGEINFO_STATEINFO']._serialized_start = 1256
_globals['_USER_VIRTUALIMAGEINFO_STATEINFO']._serialized_end = 1281
_globals['_USER_USERGROWTH']._serialized_start = 1283
_globals['_USER_USERGROWTH']._serialized_end = 1313
_globals['_USER']._serialized_end = 1125
_globals['_USER_ICON']._serialized_start = 699
_globals['_USER_ICON']._serialized_end = 719
_globals['_USER_PRIVSETS']._serialized_start = 722
_globals['_USER_PRIVSETS']._serialized_end = 893
_globals['_USER_LIKEFORUMINFO']._serialized_start = 895
_globals['_USER_LIKEFORUMINFO']._serialized_end = 948
_globals['_USER_USERVIPINFO']._serialized_start = 950
_globals['_USER_USERVIPINFO']._serialized_end = 998
_globals['_USER_TSHOWINFO']._serialized_start = 1000
_globals['_USER_TSHOWINFO']._serialized_end = 1025
_globals['_USER_NEWGODINFO']._serialized_start = 1027
_globals['_USER_NEWGODINFO']._serialized_end = 1093
_globals['_USER_USERGROWTH']._serialized_start = 1095
_globals['_USER_USERGROWTH']._serialized_end = 1125
30 changes: 0 additions & 30 deletions aiotieba/api/agree_vimage/_api.py

This file was deleted.

4 changes: 2 additions & 2 deletions aiotieba/api/get_bawu_perm/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ def parse_body(body: bytes) -> BawuPerm:
if code := res_json['no']:
raise TiebaServerError(code, res_json['error'])

data_dict = res_json['data']
perm = BawuPerm.from_tbdata(data_dict)
data_map = res_json['data']
perm = BawuPerm.from_tbdata(data_map)

return perm

Expand Down
6 changes: 3 additions & 3 deletions aiotieba/api/get_comments/_classdef.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def _frags():
else:
from ...logging import get_logger as LOG

LOG().warning(f"Unknown fragment type. type={_type} proto={proto}")
LOG().warning("Unknown fragment type. type=%s proto=%s", _type, proto)

objs = list(_frags())

Expand Down Expand Up @@ -614,7 +614,7 @@ def _frags():
else:
from ...logging import get_logger as LOG

LOG().warning(f"Unknown fragment type. type={_type} proto={proto}")
LOG().warning("Unknown fragment type. type=%s proto=%s", _type, proto)

objs = list(_frags())

Expand Down Expand Up @@ -766,7 +766,7 @@ def __hash__(self) -> int:
@cached_property
def text(self) -> str:
if self.sign:
text = f'{self.contents.text}\n{self.sign}'
text = f"{self.contents.text}\n{self.sign}"
else:
text = self.contents.text
return text
Expand Down
2 changes: 0 additions & 2 deletions aiotieba/api/get_god_threads/__init__.py

This file was deleted.

45 changes: 0 additions & 45 deletions aiotieba/api/get_god_threads/_classdef.py

This file was deleted.

2 changes: 1 addition & 1 deletion aiotieba/api/get_group_msg/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def pack_proto(account: Account, group_ids: list[int], msg_ids: list[int], get_t
group_proto.groupId = group_id
group_proto.lastMsgId = msg_id
req_proto.data.gettype = str(get_type)
req_proto.cuid = f"{account.cuid}|com.baidu.tieba_mini{POST_VERSION}"
req_proto.cuid = f'{account.cuid}|com.baidu.tieba_mini{POST_VERSION}'

return req_proto.SerializeToString()

Expand Down
6 changes: 5 additions & 1 deletion aiotieba/api/get_images/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ def parse_body(body: bytes) -> Image:


async def _request_bytes(http_core: HttpCore, url: yarl.URL) -> bytes:
request = http_core.pack_web_get_request(url, [])
request = http_core.pack_web_get_request(
url,
[],
extra_headers=[(aiohttp.hdrs.REFERER, "tieba.baidu.com")],
)

body = await http_core.net_core.send_request(request, read_bufsize=256 * 1024, headers_checker=_headers_checker)

Expand Down
16 changes: 5 additions & 11 deletions aiotieba/api/get_posts/_classdef.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from ...enums import Gender, PrivLike, PrivReply
from ...exception import TbErrorExt
from .._classdef import Containers, TypeMessage, VirtualImage, VoteInfo
from .._classdef import Containers, TypeMessage, VoteInfo
from .._classdef.contents import (
_IMAGEHASH_EXP,
FragAt,
Expand All @@ -19,8 +19,6 @@
TypeFragText,
)

VirtualImage_p = VirtualImage

FragText_p = FragText_pt = FragText_pc = FragText
FragEmoji_p = FragEmoji_pt = FragEmoji_pc = FragEmoji
FragAt_p = FragAt_pt = FragAt_pc = FragAt
Expand Down Expand Up @@ -199,7 +197,7 @@ def _frags():
else:
from ...logging import get_logger as LOG

LOG().warning(f"Unknown fragment type. type={_type} proto={proto}")
LOG().warning("Unknown fragment type. type=%s proto=%s", _type, proto)

objs = list(_frags())

Expand Down Expand Up @@ -287,7 +285,7 @@ def _frags():
else:
from ...logging import get_logger as LOG

LOG().warning(f"Unknown fragment type. type={_type} proto={proto}")
LOG().warning("Unknown fragment type. type=%s proto=%s", _type, proto)

objs = list(_frags())

Expand Down Expand Up @@ -513,7 +511,6 @@ class Post:
pid (int): 回复id
user (UserInfo_p): 发布者的用户信息
author_id (int): 发布者的user_id
vimage (VirtualImage_p): 虚拟形象信息
floor (int): 楼层数
reply_num (int): 楼中楼数
Expand All @@ -534,7 +531,6 @@ class Post:
pid: int = 0
user: UserInfo_p = dcs.field(default_factory=UserInfo_p)
author_id: int = 0
vimage: VirtualImage_p = dcs.field(default_factory=VirtualImage_p)

floor: int = 0
reply_num: int = 0
Expand All @@ -551,7 +547,6 @@ def from_tbdata(data_proto: TypeMessage) -> Post:
is_aimeme = bool(data_proto.sprite_meme_info.meme_id)
pid = data_proto.id
author_id = data_proto.author_id
vimage = VirtualImage_p.from_tbdata(data_proto)
floor = data_proto.floor
reply_num = data_proto.sub_post_number
agree = data_proto.agree.agree_num
Expand All @@ -568,7 +563,6 @@ def from_tbdata(data_proto: TypeMessage) -> Post:
pid,
None,
author_id,
vimage,
floor,
reply_num,
agree,
Expand All @@ -586,7 +580,7 @@ def __hash__(self) -> int:
@cached_property
def text(self) -> str:
if self.sign:
text = f'{self.contents.text}\n{self.sign}'
text = f"{self.contents.text}\n{self.sign}"
else:
text = self.contents.text
return text
Expand Down Expand Up @@ -775,7 +769,7 @@ def _frags():
else:
from ...logging import get_logger as LOG

LOG().warning(f"Unknown fragment type. type={_type} proto={proto}")
LOG().warning("Unknown fragment type. type=%s proto=%s", _type, proto)

objs = list(_frags())

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from ._api import parse_body, request
from ._classdef import RecoverThread
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,31 @@
from ...core import HttpCore
from ...exception import TiebaServerError
from ...helper import parse_json
from ._classdef import GodThreads
from ._classdef import RecoverThread


def parse_body(body: bytes) -> GodThreads:
def parse_body(body: bytes) -> RecoverThread:
res_json = parse_json(body)
if code := res_json['no']:
raise TiebaServerError(code, res_json['error'])

god_threads = GodThreads.from_tbdata(res_json)
data_map = res_json['data']
rec_thread = RecoverThread.from_tbdata(data_map)

return god_threads
return rec_thread


async def request(http_core: HttpCore, pn: int, rn: int) -> GodThreads:
async def request(http_core: HttpCore, fid: int, tid: int) -> RecoverThread:
params = [
('pn', pn),
('rn', rn),
('forum_id', fid),
('thread_id', tid),
('type', 1),
('sub_type', 1),
]

request = http_core.pack_web_get_request(
yarl.URL.build(scheme="https", host=WEB_BASE_HOST, path="/mo/q/activity/getActivityThreadList"), params
yarl.URL.build(scheme="https", host=WEB_BASE_HOST, path="/mo/q/bawu/getRecoverInfo"), params
)

body = await http_core.net_core.send_request(request, read_bufsize=128 * 1024)
body = await http_core.net_core.send_request(request, read_bufsize=16 * 1024)
return parse_body(body)
Loading

0 comments on commit 92fe0f1

Please sign in to comment.