Skip to content

Commit

Permalink
Merge pull request #200 from Starry-OvO/develop
Browse files Browse the repository at this point in the history
Update 4.4.5
  • Loading branch information
lumina37 authored Jun 6, 2024
2 parents de52ae5 + 6e9af6b commit 2be7657
Show file tree
Hide file tree
Showing 25 changed files with 93 additions and 68 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
ref: develop

- name: Setup Rye
uses: eifinger/setup-rye@v2
uses: eifinger/setup-rye@v3

- name: Pin Py${{ matrix.python-version }}
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/Pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
uses: actions/checkout@v4

- name: Setup Rye
uses: eifinger/setup-rye@v2
uses: eifinger/setup-rye@v3

- name: Install dependencies
run: rye sync -q
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.17.0
uses: pypa/cibuildwheel@v2.18.1

- uses: actions/upload-artifact@v4
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*.py[cd]
__pycache__

log/
dist/
build/

Expand Down
2 changes: 1 addition & 1 deletion aiotieba/api/_classdef/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def __hash__(self) -> int:
def __bool__(self) -> bool:
return bool(self.user_id)

def __ior__(self, obj: "UserInfo") -> "UserInfo":
def __ior__(self, obj) -> "UserInfo":
for field in dcs.fields(obj):
if hasattr(self, field.name):
val = getattr(obj, field.name)
Expand Down
28 changes: 20 additions & 8 deletions aiotieba/api/get_bawu_postlogs/_api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime
import time
from typing import Optional
from urllib.parse import quote

Expand Down Expand Up @@ -38,17 +39,28 @@ async def request(
params.append(('op_type', op_type))

if search_value:
search_value = quote(search_value)
extend_params = [
('svalue', search_value),
('stype', 'post_uname' if search_type == BawuSearchType.USER else 'op_uname'),
]
if search_type == BawuSearchType.USER:
search_value = quote(search_value)
extend_params = [
('svalue', search_value),
('stype', 'post_uname'),
]
else:
extend_params = [
('svalue', search_value),
('stype', 'op_uname'),
]
params += extend_params

if start_dt or end_dt:
if start_dt:
begin = int(start_dt.timestamp())
if end_dt is None:
end = int(time.time())
else:
end = int(end_dt.timestamp())
extend_params = [
('end', int(end_dt.timestamp())),
('begin', int(start_dt.timestamp())),
('end', end),
('begin', begin),
]
params += extend_params

Expand Down
28 changes: 20 additions & 8 deletions aiotieba/api/get_bawu_userlogs/_api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime
import time
from typing import Optional
from urllib.parse import quote

Expand Down Expand Up @@ -38,17 +39,28 @@ async def request(
params.append(('op_type', op_type))

if search_value:
search_value = quote(search_value)
extend_params = [
('svalue', search_value),
('stype', 'post_uname' if search_type == BawuSearchType.USER else 'op_uname'),
]
if search_type == BawuSearchType.USER:
search_value = quote(search_value)
extend_params = [
('svalue', search_value),
('stype', 'post_uname'),
]
else:
extend_params = [
('svalue', search_value),
('stype', 'op_uname'),
]
params += extend_params

if start_dt or end_dt:
if start_dt:
begin = int(start_dt.timestamp())
if end_dt is None:
end = int(time.time())
else:
end = int(end_dt.timestamp())
extend_params = [
('begin', int(start_dt.timestamp())),
('end', int(end_dt.timestamp())),
('end', end),
('begin', begin),
]
params += extend_params

Expand Down
8 changes: 5 additions & 3 deletions aiotieba/api/get_cid/_api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Dict
from typing import Dict, List, Union

import yarl

Expand All @@ -7,8 +7,10 @@
from ...exception import TiebaServerError
from ...helper import parse_json

TypeCates = List[Dict[str, Union[str, int]]]

def parse_body(body: bytes) -> Dict[str, str]:

def parse_body(body: bytes) -> TypeCates:
res_json = parse_json(body)
if code := int(res_json['error_code']):
raise TiebaServerError(code, res_json['error_msg'])
Expand All @@ -18,7 +20,7 @@ def parse_body(body: bytes) -> Dict[str, str]:
return cates


async def request(http_core: HttpCore, fname: str) -> Dict[str, str]:
async def request(http_core: HttpCore, fname: str) -> TypeCates:
data = [
('BDUSS', http_core.account.BDUSS),
('word', fname),
Expand Down
2 changes: 1 addition & 1 deletion aiotieba/api/get_recovers/_classdef.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def show_name(self) -> str:

@cached_property
def log_name(self) -> str:
return self.user_name if self.user_name else f"{self.nick_name_new}/{self.portrait}"
return self.user_name or f"{self.nick_name_new}/{self.portrait}"


@dcs.dataclass
Expand Down
2 changes: 1 addition & 1 deletion aiotieba/api/get_replys/_classdef.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def show_name(self) -> str:

@cached_property
def log_name(self) -> str:
return self.user_name if self.user_name else f"{self.nick_name_new}/{self.user_id}"
return self.user_name or f"{self.nick_name_new}/{self.user_id}"


@dcs.dataclass
Expand Down
2 changes: 1 addition & 1 deletion aiotieba/api/get_selfinfo_initNickname/_classdef.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ def nick_name(self) -> str:

@cached_property
def log_name(self) -> str:
return self.user_name if self.user_name else f"{self.nick_name_old}/{self.tieba_uid}"
return self.user_name or f"{self.nick_name_old}/{self.tieba_uid}"
8 changes: 3 additions & 5 deletions aiotieba/api/get_tab_map/_api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Dict

import yarl

from ...const import APP_BASE_HOST, APP_SECURE_SCHEME, MAIN_VERSION
Expand All @@ -20,7 +18,7 @@ def pack_proto(account: Account, fname: str) -> bytes:
return req_proto.SerializeToString()


def parse_body(body: bytes) -> Dict[str, int]:
def parse_body(body: bytes) -> TabMap:
res_proto = SearchPostForumResIdl_pb2.SearchPostForumResIdl()
res_proto.ParseFromString(body)

Expand All @@ -33,7 +31,7 @@ def parse_body(body: bytes) -> Dict[str, int]:
return tab_map


async def request_http(http_core: HttpCore, fname: str) -> Dict[str, int]:
async def request_http(http_core: HttpCore, fname: str) -> TabMap:
data = pack_proto(http_core.account, fname)

request = http_core.pack_proto_request(
Expand All @@ -47,7 +45,7 @@ async def request_http(http_core: HttpCore, fname: str) -> Dict[str, int]:
return parse_body(body)


async def request_ws(ws_core: WsCore, fname: str) -> Dict[str, int]:
async def request_ws(ws_core: WsCore, fname: str) -> TabMap:
data = pack_proto(ws_core.account, fname)

response = await ws_core.send(data, CMD)
Expand Down
2 changes: 1 addition & 1 deletion aiotieba/api/get_uinfo_panel/_classdef.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,4 @@ def show_name(self) -> str:

@cached_property
def log_name(self) -> str:
return self.user_name if self.user_name else f"{self.nick_name_new}/{self.portrait}"
return self.user_name or f"{self.nick_name_new}/{self.portrait}"
11 changes: 5 additions & 6 deletions aiotieba/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@
from .helper.cache import ForumInfoCache
from .helper.utils import handle_exception, is_portrait, is_user_name
from .logging import get_logger as LOG
from .typing import TypeUserInfo

if TYPE_CHECKING:
import datetime
Expand Down Expand Up @@ -152,7 +151,7 @@ class Client:
account (Account, optional): Account实例 该字段会覆盖前两个参数. Defaults to None.
try_ws (bool, optional): 尝试使用websocket接口. Defaults to False.
proxy (bool | ProxyConfig, optional): True则使用环境变量代理 False则禁用代理 输入ProxyConfig实例以手动配置代理. Defaults to False.
timeout (TimeoutConfig, optional): 超时配置. Defaults to TimeoutConfig().
timeout (TimeoutConfig, optional): 超时配置. Defaults to None.
loop (asyncio.AbstractEventLoop, optional): 事件循环. Defaults to None.
"""

Expand All @@ -172,7 +171,7 @@ def __init__(
account: Optional[Account] = None,
try_ws: bool = False,
proxy: Union[bool, ProxyConfig] = False,
timeout: TimeoutConfig = TimeoutConfig,
timeout: Optional[TimeoutConfig] = None,
loop: Optional[asyncio.AbstractEventLoop] = None,
) -> None:
if loop is None:
Expand Down Expand Up @@ -633,7 +632,7 @@ async def _get_uinfo_panel(self, name_or_portrait: str) -> get_uinfo_panel.UserI

return await get_uinfo_panel.request(self._http_core, name_or_portrait)

async def get_user_info(self, id_: Union[str, int], /, require: ReqUInfo = ReqUInfo.ALL) -> TypeUserInfo:
async def get_user_info(self, id_: Union[str, int], /, require: ReqUInfo = ReqUInfo.ALL) -> UserInfo:
"""
获取用户信息
Expand All @@ -642,7 +641,7 @@ async def get_user_info(self, id_: Union[str, int], /, require: ReqUInfo = ReqUI
require (ReqUInfo): 指示需要获取的字段
Returns:
TypeUserInfo: 用户信息
UserInfo: 用户信息
"""

if not id_:
Expand Down Expand Up @@ -1834,7 +1833,7 @@ async def __get_cid(self, fname_or_fid: Union[str, int], /, cname: str = '') ->
cid = 0
for item in cates:
if cname == item['class_name']:
cid = int(item['class_id'])
cid = item['class_id']
break

return cid
Expand Down
6 changes: 3 additions & 3 deletions aiotieba/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class TimeoutConfig:
ws_read (float, optional): 从发送websocket数据到结束等待响应的超时时间. Defaults to 8.0.
ws_keepalive (float, optional): websocket在长达ws_keepalive的时间内未发生IO则发送close信号关闭连接. Defaults to 300.0.
ws_heartbeat (float, optional): websocket心跳间隔. 为None则不发送心跳. Defaults to None.
dns_ttl (float, optional): dns的本地缓存超时时间. Defaults to 600.0.
dns_ttl (int, optional): dns的本地缓存超时时间. Defaults to 600.
Note:
所有时间均以秒为单位
Expand All @@ -60,7 +60,7 @@ class TimeoutConfig:
ws_read: float = 8.0
ws_keepalive: float = 300.0
ws_heartbeat: Optional[float] = None
dns_ttl: float = 600.0
dns_ttl: int = 600

def __init__(
self,
Expand All @@ -72,7 +72,7 @@ def __init__(
ws_read: float = 8.0,
ws_keepalive: float = 300.0,
ws_heartbeat: Optional[float] = None,
dns_ttl: float = 600.0,
dns_ttl: int = 600,
) -> None:
self.http = aiohttp.ClientTimeout(connect=http_acquire_conn, sock_read=http_read, sock_connect=http_connect)
self.http_keepalive = http_keepalive
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.59.1.0"
MAIN_VERSION = "12.62.1.0"
POST_VERSION = "12.35.1.0"

APP_SECURE_SCHEME = "https"
Expand Down
7 changes: 4 additions & 3 deletions aiotieba/core/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import dataclasses as dcs
import random
import urllib.parse
from http.cookies import Morsel
from typing import Dict, List, Optional, Tuple

import aiohttp
Expand Down Expand Up @@ -77,11 +78,11 @@ def __init__(self, account: Account, net_core: NetCore, loop: Optional[asyncio.A
def set_account(self, new_account: Account) -> None:
self.account = new_account

BDUSS_morsel = aiohttp.cookiejar.Morsel()
BDUSS_morsel = Morsel()
BDUSS_morsel.set('BDUSS', new_account.BDUSS, new_account.BDUSS)
BDUSS_morsel['domain'] = "baidu.com"
self.web.cookie_jar._cookies[("baidu.com", "/")]['BDUSS'] = BDUSS_morsel
STOKEN_morsel = aiohttp.cookiejar.Morsel()
STOKEN_morsel = Morsel()
STOKEN_morsel.set('STOKEN', new_account.STOKEN, new_account.STOKEN)
STOKEN_morsel['domain'] = "tieba.baidu.com"
self.web.cookie_jar._cookies[("tieba.baidu.com", "/")]['STOKEN'] = STOKEN_morsel
Expand Down Expand Up @@ -129,7 +130,7 @@ def pack_proto_request(self, url: yarl.URL, data: bytes) -> aiohttp.ClientReques
aiohttp.ClientRequest
"""

writer = aiohttp.MultipartWriter('form-data', boundary=f"*-reverse1999-{random.randint(0,9)}")
writer = aiohttp.MultipartWriter('form-data', boundary=f"*-reverse1999-{random.randint(0, 9)}")
payload_headers = {
aiohttp.hdrs.CONTENT_DISPOSITION: aiohttp.helpers.content_disposition_header(
'form-data', name='data', filename='file'
Expand Down
10 changes: 5 additions & 5 deletions aiotieba/core/net.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import asyncio
import dataclasses as dcs
from typing import Callable
from typing import Callable, Optional

import aiohttp

Expand All @@ -24,8 +24,8 @@ class NetCore:
Args:
connector (aiohttp.TCPConnector): 用于生成TCP连接的连接器
proxy (ProxyConfig, optional): 代理配置. Defaults to ProxyConfig().
timeout (TimeoutConfig, optional): 超时配置. Defaults to TimeoutConfig().
proxy (ProxyConfig, optional): 代理配置. Defaults to None.
timeout (TimeoutConfig, optional): 超时配置. Defaults to None.
"""

connector: aiohttp.TCPConnector
Expand All @@ -35,8 +35,8 @@ class NetCore:
def __init__(
self,
connector: aiohttp.TCPConnector,
proxy: ProxyConfig = ProxyConfig,
timeout: TimeoutConfig = TimeoutConfig,
proxy: Optional[ProxyConfig] = None,
timeout: Optional[TimeoutConfig] = None,
) -> None:
self.connector = connector

Expand Down
2 changes: 1 addition & 1 deletion aiotieba/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __bool__(self) -> bool:
def __int__(self) -> int:
return int(bool(self))

def __repr__(self) -> int:
def __repr__(self) -> str:
return str(bool(self))

def __hash__(self) -> int:
Expand Down
4 changes: 2 additions & 2 deletions aiotieba/helper/crypto/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
from .crypto import sign as _sign


def sign(data: List[Tuple[str, Union[str, int]]]) -> List[Tuple[str, str]]:
def sign(data: List[Tuple[str, Union[str, int]]]) -> List[Tuple[str, Union[str, int]]]:
"""
为参数元组列表添加贴吧客户端签名
Args:
data (list[tuple[str, str | int]]): 参数元组列表
Returns:
list[tuple[str, str]]: 签名后的form参数元组列表
list[tuple[str, str | int]]: 签名后的form参数元组列表
"""

data.append(('sign', _sign(data)))
Expand Down
Loading

0 comments on commit 2be7657

Please sign in to comment.