-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #176 from Starry-OvO/develop
Update 4.2.0
- Loading branch information
Showing
34 changed files
with
579 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "4.1.0" | ||
__version__ = "4.2.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from ._api import parse_body, request | ||
from ._classdef import Forum |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import yarl | ||
|
||
from ...const import APP_BASE_HOST, APP_SECURE_SCHEME | ||
from ...core import HttpCore | ||
from ...exception import TiebaServerError | ||
from ...helper import parse_json | ||
from ._classdef import Forum | ||
|
||
|
||
def parse_body(body: bytes) -> Forum: | ||
res_json = parse_json(body) | ||
if code := int(res_json['error_code']): | ||
raise TiebaServerError(code, res_json['error_msg']) | ||
|
||
forum_dict = res_json['forum'] | ||
forum = Forum.from_tbdata(forum_dict) | ||
|
||
return forum | ||
|
||
|
||
async def request(http_core: HttpCore, fname: str) -> Forum: | ||
data = [('kw', fname)] | ||
|
||
request = http_core.pack_form_request( | ||
yarl.URL.build(scheme=APP_SECURE_SCHEME, host=APP_BASE_HOST, path="/c/f/frs/frsBottom"), data | ||
) | ||
|
||
body = await http_core.net_core.send_request(request, read_bufsize=8 * 1024) | ||
return parse_body(body) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import dataclasses as dcs | ||
from typing import Mapping | ||
|
||
from ...exception import TbErrorExt | ||
|
||
|
||
@dcs.dataclass | ||
class Forum(TbErrorExt): | ||
""" | ||
贴吧信息 | ||
Attributes: | ||
err (Exception | None): 捕获的异常 | ||
fid (int): 贴吧id | ||
fname (str): 贴吧名 | ||
category (str): 一级分类 | ||
subcategory (str): 二级分类 | ||
small_avatar (str): 吧头像(小) | ||
slogan (str): 吧标语 | ||
member_num (int): 吧会员数 | ||
post_num (int): 发帖量 | ||
thread_num (int): 主题帖数 | ||
has_bawu (bool): 是否有吧务 | ||
""" | ||
|
||
fid: int = 0 | ||
fname: str = '' | ||
|
||
category: str = '' | ||
subcategory: str = '' | ||
|
||
small_avatar: str = "" | ||
slogan: str = "" | ||
member_num: int = 0 | ||
post_num: int = 0 | ||
thread_num: int = 0 | ||
|
||
has_bawu: bool = False | ||
|
||
@staticmethod | ||
def from_tbdata(data_map: Mapping) -> "Forum": | ||
fid = data_map['id'] | ||
fname = data_map['name'] | ||
category = data_map['first_class'] | ||
subcategory = data_map['second_class'] | ||
small_avatar = data_map['avatar'] | ||
slogan = data_map['slogan'] | ||
member_num = data_map['member_num'] | ||
post_num = data_map['post_num'] | ||
thread_num = data_map['thread_num'] | ||
has_bawu = 'managers' in data_map | ||
return Forum( | ||
fid, fname, category, subcategory, small_avatar, slogan, member_num, post_num, thread_num, has_bawu | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from ._api import parse_body, request | ||
from ._classdef import RankForum, RankForums |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import bs4 | ||
import yarl | ||
|
||
from ...const import WEB_BASE_HOST | ||
from ...core import HttpCore | ||
from ...enums import RankForumType | ||
from ._classdef import RankForums | ||
|
||
|
||
def parse_body(body: bytes) -> RankForums: | ||
soup = bs4.BeautifulSoup(body, 'lxml') | ||
bawu_postlogs = RankForums.from_tbdata(soup) | ||
|
||
return bawu_postlogs | ||
|
||
|
||
async def request(http_core: HttpCore, fname: str, pn: int, rank_type: RankForumType) -> RankForums: | ||
params = [ | ||
('kw', fname), | ||
('type', int(rank_type)), | ||
('pn', pn), | ||
('ie', 'utf-8'), | ||
] | ||
|
||
request = http_core.pack_web_get_request( | ||
yarl.URL.build(scheme="https", host=WEB_BASE_HOST, path="/sign/index"), params | ||
) | ||
|
||
body = await http_core.net_core.send_request(request, read_bufsize=8 * 1024) | ||
return parse_body(body) |
Oops, something went wrong.