mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2025-06-06 20:06:12 +08:00
add tag for bilibili
This commit is contained in:
parent
4852337468
commit
dbaaee5df9
@ -1,4 +1,3 @@
|
|||||||
from collections import defaultdict
|
|
||||||
import json
|
import json
|
||||||
from typing import Any, Optional
|
from typing import Any, Optional
|
||||||
|
|
||||||
@ -18,7 +17,7 @@ class Bilibili(Platform):
|
|||||||
# 5: "短视频"
|
# 5: "短视频"
|
||||||
}
|
}
|
||||||
platform_name = 'bilibili'
|
platform_name = 'bilibili'
|
||||||
enable_tag = False
|
enable_tag = True
|
||||||
enabled = True
|
enabled = True
|
||||||
is_common = True
|
is_common = True
|
||||||
schedule_interval = 10
|
schedule_interval = 10
|
||||||
@ -65,7 +64,7 @@ class Bilibili(Platform):
|
|||||||
raise CategoryNotSupport()
|
raise CategoryNotSupport()
|
||||||
|
|
||||||
def get_tags(self, raw_post: RawPost) -> list[Tag]:
|
def get_tags(self, raw_post: RawPost) -> list[Tag]:
|
||||||
return []
|
return [*map(lambda tp: tp['topic_name'], raw_post['display']['topic_info']['topic_details'])]
|
||||||
|
|
||||||
async def parse(self, raw_post: RawPost) -> Post:
|
async def parse(self, raw_post: RawPost) -> Post:
|
||||||
card_content = json.loads(raw_post['card'])
|
card_content = json.loads(raw_post['card'])
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
|
from abc import abstractmethod
|
||||||
import time
|
import time
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from typing import Any, Optional
|
from typing import Any, Collection, Optional
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
from nonebot import logger
|
from nonebot import logger
|
||||||
@ -47,36 +48,38 @@ class PlatformProto(metaclass=RegistryMeta):
|
|||||||
is_common: bool
|
is_common: bool
|
||||||
schedule_interval: int
|
schedule_interval: int
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
async def fetch_new_post(self, target: Target, users: list[User]) -> list[tuple[User, list[Post]]]:
|
async def fetch_new_post(self, target: Target, users: list[User]) -> list[tuple[User, list[Post]]]:
|
||||||
...
|
...
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@abstractmethod
|
||||||
async def get_account_name(target: Target) -> Optional[str]:
|
async def get_account_name(target: Target) -> Optional[str]:
|
||||||
"return the username(name) of the target"
|
"return the username(name) of the target"
|
||||||
raise NotImplementedError()
|
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
def get_id(self, post: RawPost) -> Any:
|
def get_id(self, post: RawPost) -> Any:
|
||||||
"Get post id of given RawPost"
|
"Get post id of given RawPost"
|
||||||
raise NotImplementedError()
|
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
def get_date(self, post: RawPost) -> Optional[int]:
|
def get_date(self, post: RawPost) -> Optional[int]:
|
||||||
"Get post timestamp and return, return None if can't get the time"
|
"Get post timestamp and return, return None if can't get the time"
|
||||||
raise NotImplementedError()
|
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
def get_category(self, post: RawPost) -> Optional[Category]:
|
def get_category(self, post: RawPost) -> Optional[Category]:
|
||||||
"Return category of given Rawpost"
|
"Return category of given Rawpost"
|
||||||
raise NotImplementedError()
|
|
||||||
|
|
||||||
def get_tags(self, raw_post: RawPost) -> Optional[list[Tag]]:
|
@abstractmethod
|
||||||
|
def get_tags(self, raw_post: RawPost) -> Optional[Collection[Tag]]:
|
||||||
"Return Tag list of given RawPost"
|
"Return Tag list of given RawPost"
|
||||||
raise NotImplementedError()
|
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
async def parse(self, raw_post: RawPost) -> Post:
|
async def parse(self, raw_post: RawPost) -> Post:
|
||||||
"parse RawPost into post"
|
"parse RawPost into post"
|
||||||
raise NotImplementedError()
|
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
def filter_platform_custom(self, post: RawPost) -> bool:
|
def filter_platform_custom(self, post: RawPost) -> bool:
|
||||||
raise NotImplementedError()
|
"a customed filter"
|
||||||
|
|
||||||
async def _parse_with_cache(self, post: RawPost) -> Post:
|
async def _parse_with_cache(self, post: RawPost) -> Post:
|
||||||
post_id = self.get_id(post)
|
post_id = self.get_id(post)
|
||||||
@ -93,6 +96,7 @@ class PlatformProto(metaclass=RegistryMeta):
|
|||||||
return self.cache[post_id]
|
return self.cache[post_id]
|
||||||
|
|
||||||
def _do_filter_common(self, raw_post_list: list[RawPost], exists_posts_set: set) -> list[RawPost]:
|
def _do_filter_common(self, raw_post_list: list[RawPost], exists_posts_set: set) -> list[RawPost]:
|
||||||
|
import ipdb; ipdb.set_trace()
|
||||||
res = []
|
res = []
|
||||||
for raw_post in raw_post_list:
|
for raw_post in raw_post_list:
|
||||||
post_id = self.get_id(raw_post)
|
post_id = self.get_id(raw_post)
|
||||||
@ -152,9 +156,9 @@ class Platform(PlatformProto):
|
|||||||
for key, val in self.categories.items():
|
for key, val in self.categories.items():
|
||||||
self.reverse_category[val] = key
|
self.reverse_category[val] = key
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
async def get_sub_list(self, target: Target) -> list[RawPost]:
|
async def get_sub_list(self, target: Target) -> list[RawPost]:
|
||||||
"Get post list of the given target"
|
"Get post list of the given target"
|
||||||
raise NotImplementedError()
|
|
||||||
|
|
||||||
async def filter_common(self, target: Target, raw_post_list: list[RawPost]) -> list[RawPost]:
|
async def filter_common(self, target: Target, raw_post_list: list[RawPost]) -> list[RawPost]:
|
||||||
if not self.inited.get(target, False) and plugin_config.hk_reporter_init_filter:
|
if not self.inited.get(target, False) and plugin_config.hk_reporter_init_filter:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user