Skip to content

Commit

Permalink
Merge pull request #152 from Starry-OvO/develop
Browse files Browse the repository at this point in the history
Update 3.7.5
  • Loading branch information
lumina37 authored Dec 5, 2023
2 parents edda6ef + 050a2f7 commit a004686
Show file tree
Hide file tree
Showing 21 changed files with 216 additions and 68 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ jobs:

strategy:
matrix:
python-version: ["3.8", "3.11", "3.12"]
python-version: ["3.8", "3.12"]

steps:
- name: Checkout develop
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: develop

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/Pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install dependencies
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/Publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
os: ["ubuntu-latest", "windows-latest", "macos-latest"]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Build wheels
uses: pypa/[email protected]
Expand All @@ -28,7 +28,7 @@ jobs:
name: Build source distribution
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Build sdist
run: pipx run build --sdist
Expand Down
2 changes: 1 addition & 1 deletion aiotieba/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "3.7.4"
__version__ = "3.7.5"
16 changes: 10 additions & 6 deletions aiotieba/api/get_recovers/_api.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Optional

import yarl

from ...const import WEB_BASE_HOST
Expand All @@ -17,17 +19,19 @@ def parse_body(body: bytes) -> Recovers:
return recovers


async def request(http_core: HttpCore, fid: int, name: str, pn: int) -> Recovers:
async def request(http_core: HttpCore, fid: int, user_id: Optional[int], pn: int, rn: int) -> Recovers:
params = [
('fn', '-'),
('fid', fid),
('word', name),
('is_ajax', '1'),
('rn', rn),
('forum_id', fid),
('pn', pn),
('type', 1),
('sub_type', 1),
]
if user_id:
params.append(('uid', user_id))

request = http_core.pack_web_get_request(
yarl.URL.build(scheme="https", host=WEB_BASE_HOST, path="/mo/q/bawurecover"), params
yarl.URL.build(scheme="https", host=WEB_BASE_HOST, path="/mo/q/manage/getRecoverList"), params
)

__log__ = "fid={fid}" # noqa: F841
Expand Down
190 changes: 169 additions & 21 deletions aiotieba/api/get_recovers/_classdef.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,122 @@
from typing import Mapping, Optional

import bs4

from .._classdef import Containers


class UserInfo_rec(object):
"""
用户信息
Attributes:
portrait (str): portrait
user_name (str): 用户名
nick_name_new (str): 新版昵称
nick_name (str): 用户昵称
show_name (str): 显示名称
log_name (str): 用于在日志中记录用户信息
"""

__slots__ = [
'_portrait',
'_user_name',
'_nick_name_new',
]

def _init(self, data_map: Mapping) -> "UserInfo_rec":
if '?' in (portrait := data_map['portrait']):
self._portrait = portrait[:-13]
else:
self._portrait = portrait
self._user_name = data_map['user_name']
self._nick_name_new = data_map['user_nickname']
return self

def _init_null(self) -> "UserInfo_rec":
self._portrait = ''
self._user_name = ''
self._nick_name_new = ''
return self

def __str__(self) -> str:
return self._user_name or self._portrait

def __repr__(self) -> str:
return str(
{
'portrait': self._portrait,
'show_name': self.show_name,
}
)

def __eq__(self, obj: "UserInfo_rec") -> bool:
return self._portrait == obj._portrait

def __hash__(self) -> int:
return hash(self._portrait)

def __int__(self) -> int:
return hash(self._portrait)

def __bool__(self) -> bool:
return bool(self._portrait)

@property
def portrait(self) -> str:
"""
用户portrait
Note:
唯一 不可变 不可为空
"""

return self._portrait

@property
def user_name(self) -> str:
"""
用户名
Note:
唯一 可变 可为空\n
请注意与用户昵称区分
"""

return self._user_name

@property
def nick_name_new(self) -> str:
"""
新版昵称
"""

return self._nick_name_new

@property
def nick_name(self) -> str:
"""
用户昵称
"""

return self._nick_name_new

@property
def show_name(self) -> str:
"""
显示名称
"""

return self._nick_name_new or self._user_name

@property
def log_name(self) -> str:
"""
用于在日志中记录用户信息
"""

return self._user_name if self._user_name else f"{self._nick_name_new}/{self._portrait}"


class Recover(object):
"""
待恢复帖子信息
Expand All @@ -13,36 +125,51 @@ class Recover(object):
text (str): 文本内容
tid (int): 所在主题帖id
pid (int): 回复id
user (UserInfo_rec): 发布者的用户信息
op_show_name (str): 操作人显示名称
op_time (int): 操作时间
is_floor (bool): 是否为楼中楼
is_hide (bool): 是否为屏蔽
op_user_name (bool): 操作人名称
"""

__slots__ = [
'_text',
'_tid',
'_pid',
'_user',
'_is_floor',
'_is_hide',
'_op_user_name',
'_op_show_name',
'_op_time',
]

def __init__(self, data_tag: bs4.element.Tag) -> None:
id_tag = data_tag.a
self._tid = int(id_tag['attr-tid'])
self._pid = int(id_tag['attr-pid'])
self._is_hide = bool(int(id_tag['attr-isfrsmask']))
text_tag = id_tag.next_sibling.span
self._text = text_tag.string
oper_tag = id_tag.next_sibling.find('span', class_="recover_list_item_operator")
self._op_user_name = oper_tag.string[4:]
def __init__(self, data_map: Mapping) -> None:
thread_info = data_map['thread_info']
self._tid = int(thread_info['tid'])
if post_info := data_map['post_info']:
self._text = post_info['abstract']
self._pid = int(post_info['pid'])
self._user = UserInfo_rec()._init(post_info)
else:
self._text = thread_info['abstract']
self._pid = 0
self._user = UserInfo_rec()._init(thread_info)
self._is_floor = bool(data_map['is_foor']) # 百度的Code Review主要起到一个装饰的作用
self._is_hide = bool(int(data_map['is_frs_mask']))
self._op_show_name = data_map['op_info']['name']
self._op_time = int(data_map['op_info']['time'])

def __repr__(self) -> str:
return str(
{
'text': self._text,
'tid': self._tid,
'pid': self._pid,
'user': self._user.show_name,
'is_floor': self._is_floor,
'is_hide': self._is_hide,
'op_user_name': self._op_user_name,
'op_show_name': self._op_show_name,
}
)

Expand All @@ -66,10 +193,21 @@ def tid(self) -> int:
def pid(self) -> int:
"""
回复id
Note:
若为主题帖则该字段为0
"""

return self._pid

@property
def is_floor(self) -> bool:
"""
是否为楼中楼
"""

return self._is_floor

@property
def is_hide(self) -> bool:
"""
Expand All @@ -79,12 +217,23 @@ def is_hide(self) -> bool:
return self._is_hide

@property
def op_user_name(self) -> str:
def op_show_name(self) -> str:
"""
操作人名称
操作人显示名称
"""

return self._op_show_name

@property
def op_time(self) -> int:
"""
操作时间
Note:
10位时间戳 以秒为单位
"""

return self._op_user_name
return self._op_time


class Page_recover(object):
Expand All @@ -107,9 +256,9 @@ class Page_recover(object):
]

def _init(self, data_map: Mapping) -> "Page_recover":
self._page_size = data_map['size']
self._page_size = data_map['rn']
self._current_page = data_map['pn']
self._has_more = data_map['have_next']
self._has_more = data_map['has_more']
self._has_prev = self._current_page > 1
return self

Expand Down Expand Up @@ -177,8 +326,7 @@ class Recovers(Containers[Recover]):

def __init__(self, data_map: Optional[Mapping] = None) -> None:
if data_map:
data_soup = bs4.BeautifulSoup(data_map['data']['content'], 'lxml')
self._objs = [Recover(t) for t in data_soup('li')]
self._objs = [Recover(t) for t in data_map['data']['thread_list']]
self._page = Page_recover()._init(data_map['data']['page'])
else:
self._objs = []
Expand Down
12 changes: 10 additions & 2 deletions aiotieba/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1148,7 +1148,7 @@ async def get_blocks(self, fname_or_fid: Union[str, int], /, name: str = '', pn:

@handle_exception(get_recovers.Recovers)
async def get_recovers(
self, fname_or_fid: Union[str, int], /, name: str = '', pn: int = 1
self, fname_or_fid: Union[str, int], /, pn: int = 1, *, rn: int = 10, _id: Union[str, int, None] = None
) -> get_recovers.Recovers:
"""
获取pn页的待恢复帖子列表
Expand All @@ -1157,14 +1157,22 @@ async def get_recovers(
fname_or_fid (str | int): 目标贴吧的贴吧名或fid 优先fid
name (str, optional): 通过被删帖作者的用户名/昵称查询 默认为空即查询全部. Defaults to ''.
pn (int, optional): 页码. Defaults to 1.
rn (int, optional): 请求的条目数. Defaults to 10. Max to 50.
_id (str | int, optional): 用于查询的被删帖用户的id user_id / user_name / portrait 优先user_id. Defaults to None.
Returns:
Recovers: 待恢复帖子列表
"""

fid = fname_or_fid if isinstance(fname_or_fid, int) else await self.get_fid(fname_or_fid)

return await get_recovers.request(self._http_core, fid, name, pn)
if _id and not isinstance(_id, int):
user = await self.get_user_info(_id, ReqUInfo.USER_ID)
user_id = user._user_id
else:
user_id = _id

return await get_recovers.request(self._http_core, fid, user_id, pn, rn)

@handle_exception(get_bawu_userlogs.Userlogs)
async def get_bawu_userlogs(
Expand Down
2 changes: 1 addition & 1 deletion aiotieba/const.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
MAIN_VERSION = "12.50.0.0"
MAIN_VERSION = "12.51.5.1"
POST_VERSION = "12.35.1.0"

APP_SECURE_SCHEME = "https"
Expand Down
Loading

0 comments on commit a004686

Please sign in to comment.