mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2026-05-09 18:27:56 +08:00
🧑💻 使用 Ruff 包办所有格式化和检查 (#663)
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
from pathlib import Path
|
||||
from pkgutil import iter_modules
|
||||
from collections import defaultdict
|
||||
from importlib import import_module
|
||||
from pathlib import Path
|
||||
from pkgutil import iter_modules
|
||||
|
||||
from nonebot_bison.plugin_config import plugin_config
|
||||
|
||||
from ..plugin_config import plugin_config
|
||||
from .platform import Platform, make_no_target_group
|
||||
|
||||
_package_dir = str(Path(__file__).resolve().parent)
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
import re
|
||||
import html
|
||||
from typing import Any
|
||||
from functools import partial
|
||||
import html
|
||||
import re
|
||||
from typing import Any, ClassVar
|
||||
|
||||
from yarl import URL
|
||||
from httpx import AsyncClient
|
||||
from bs4 import BeautifulSoup as bs
|
||||
from pydantic import Field, BaseModel
|
||||
from httpx import AsyncClient
|
||||
from nonebot.compat import type_validate_python
|
||||
from pydantic import BaseModel, Field
|
||||
from yarl import URL
|
||||
|
||||
from nonebot_bison.post import Post
|
||||
from nonebot_bison.post.protocol import HTMLContentSupport
|
||||
from nonebot_bison.types import Category, RawPost, Target
|
||||
from nonebot_bison.utils import Site
|
||||
|
||||
from ..post import Post
|
||||
from ..utils import Site
|
||||
from ..types import Target, RawPost, Category
|
||||
from ..post.protocol import HTMLContentSupport
|
||||
from .platform import NewMessage, StatusChange
|
||||
|
||||
|
||||
@@ -58,7 +59,7 @@ class ArkBulletinResponse(ArkResponseBase):
|
||||
class ArknightsSite(Site):
|
||||
name = "arknights"
|
||||
schedule_type = "interval"
|
||||
schedule_setting = {"seconds": 30}
|
||||
schedule_setting: ClassVar[dict] = {"seconds": 30}
|
||||
|
||||
|
||||
class ArknightsPost(Post, HTMLContentSupport):
|
||||
@@ -95,7 +96,7 @@ class ArknightsPost(Post, HTMLContentSupport):
|
||||
|
||||
|
||||
class Arknights(NewMessage):
|
||||
categories = {1: "游戏公告"}
|
||||
categories: ClassVar[dict[Category, str]] = {1: "游戏公告"}
|
||||
platform_name = "arknights"
|
||||
name = "明日方舟游戏信息"
|
||||
enable_tag = False
|
||||
@@ -157,7 +158,7 @@ class Arknights(NewMessage):
|
||||
|
||||
|
||||
class AkVersion(StatusChange):
|
||||
categories = {2: "更新信息"}
|
||||
categories: ClassVar[dict[Category, str]] = {2: "更新信息"}
|
||||
platform_name = "arknights"
|
||||
name = "明日方舟游戏信息"
|
||||
enable_tag = False
|
||||
@@ -202,7 +203,7 @@ class AkVersion(StatusChange):
|
||||
|
||||
|
||||
class MonsterSiren(NewMessage):
|
||||
categories = {3: "塞壬唱片新闻"}
|
||||
categories: ClassVar[dict[Category, str]] = {3: "塞壬唱片新闻"}
|
||||
platform_name = "arknights"
|
||||
name = "明日方舟游戏信息"
|
||||
enable_tag = False
|
||||
@@ -250,7 +251,7 @@ class MonsterSiren(NewMessage):
|
||||
|
||||
|
||||
class TerraHistoricusComic(NewMessage):
|
||||
categories = {4: "泰拉记事社漫画"}
|
||||
categories: ClassVar[dict[Category, str]] = {4: "泰拉记事社漫画"}
|
||||
platform_name = "arknights"
|
||||
name = "明日方舟游戏信息"
|
||||
enable_tag = False
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from .platforms import Bilibili as Bilibili
|
||||
from .platforms import Bilibililive as Bilibililive
|
||||
from .scheduler import BilibiliSite as BilibiliSite
|
||||
from .scheduler import BililiveSite as BililiveSite
|
||||
from .platforms import BilibiliBangumi as BilibiliBangumi
|
||||
from .platforms import Bilibililive as Bilibililive
|
||||
from .scheduler import BiliBangumiSite as BiliBangumiSite
|
||||
from .scheduler import BilibiliClientManager as BilibiliClientManager
|
||||
from .scheduler import BilibiliSite as BilibiliSite
|
||||
from .scheduler import BililiveSite as BililiveSite
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
import sys
|
||||
import asyncio
|
||||
import inspect
|
||||
from collections.abc import AsyncGenerator, Awaitable, Callable, Sequence
|
||||
from collections.abc import Set as AbstractSet
|
||||
from dataclasses import dataclass
|
||||
from enum import Enum
|
||||
from functools import wraps
|
||||
from dataclasses import dataclass
|
||||
from collections.abc import Set as AbstractSet
|
||||
from collections.abc import Callable, Sequence, Awaitable, AsyncGenerator
|
||||
import inspect
|
||||
import sys
|
||||
from typing import (
|
||||
TYPE_CHECKING,
|
||||
Any,
|
||||
Concatenate,
|
||||
Generic,
|
||||
TypeVar,
|
||||
Protocol,
|
||||
NamedTuple,
|
||||
ParamSpec,
|
||||
Protocol,
|
||||
TypeAlias,
|
||||
TypedDict,
|
||||
NamedTuple,
|
||||
Concatenate,
|
||||
TypeVar,
|
||||
overload,
|
||||
runtime_checkable,
|
||||
)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from typing import Any, Literal, TypeVar, TypeAlias
|
||||
from typing import Any, Literal, TypeAlias, TypeVar
|
||||
|
||||
from pydantic import BaseModel
|
||||
from nonebot.compat import PYDANTIC_V2, ConfigDict
|
||||
from pydantic import BaseModel
|
||||
|
||||
from nonebot_bison.compat import model_rebuild
|
||||
|
||||
@@ -13,7 +13,7 @@ TBaseModel = TypeVar("TBaseModel", bound=type[BaseModel])
|
||||
def model_rebuild_recurse(cls: TBaseModel) -> TBaseModel:
|
||||
"""Recursively rebuild all BaseModel subclasses in the class."""
|
||||
if not PYDANTIC_V2:
|
||||
from inspect import isclass, getmembers
|
||||
from inspect import getmembers, isclass
|
||||
|
||||
for _, sub_cls in getmembers(cls, lambda x: isclass(x) and issubclass(x, BaseModel)):
|
||||
model_rebuild_recurse(sub_cls)
|
||||
|
||||
@@ -1,41 +1,41 @@
|
||||
import re
|
||||
import json
|
||||
from copy import deepcopy
|
||||
from enum import Enum, unique
|
||||
from typing import NamedTuple
|
||||
import json
|
||||
import re
|
||||
from typing import ClassVar, NamedTuple
|
||||
from typing_extensions import Self
|
||||
|
||||
from yarl import URL
|
||||
from nonebot import logger
|
||||
from httpx import AsyncClient
|
||||
from pydantic import Field, BaseModel, ValidationError
|
||||
from nonebot import logger
|
||||
from nonebot.compat import type_validate_json, type_validate_python
|
||||
from pydantic import BaseModel, Field, ValidationError
|
||||
from yarl import URL
|
||||
|
||||
from nonebot_bison.post.post import Post
|
||||
from nonebot_bison.compat import model_rebuild
|
||||
from nonebot_bison.utils import text_similarity, decode_unicode_escapes
|
||||
from nonebot_bison.types import Tag, Target, RawPost, ApiError, Category
|
||||
from nonebot_bison.platform.platform import CategoryNotRecognize, CategoryNotSupport, NewMessage, StatusChange
|
||||
from nonebot_bison.post.post import Post
|
||||
from nonebot_bison.types import ApiError, Category, RawPost, Tag, Target
|
||||
from nonebot_bison.utils import decode_unicode_escapes, text_similarity
|
||||
|
||||
from .retry import ApiCode352Error, retry_for_352
|
||||
from .scheduler import BilibiliSite, BililiveSite, BiliBangumiSite
|
||||
from ..platform import NewMessage, StatusChange, CategoryNotSupport, CategoryNotRecognize
|
||||
from .models import (
|
||||
PostAPI,
|
||||
UserAPI,
|
||||
PGCMajor,
|
||||
DrawMajor,
|
||||
LiveMajor,
|
||||
OPUSMajor,
|
||||
DynRawPost,
|
||||
VideoMajor,
|
||||
CommonMajor,
|
||||
DynamicType,
|
||||
ArticleMajor,
|
||||
CommonMajor,
|
||||
CoursesMajor,
|
||||
DeletedMajor,
|
||||
UnknownMajor,
|
||||
DrawMajor,
|
||||
DynamicType,
|
||||
DynRawPost,
|
||||
LiveMajor,
|
||||
LiveRecommendMajor,
|
||||
OPUSMajor,
|
||||
PGCMajor,
|
||||
PostAPI,
|
||||
UnknownMajor,
|
||||
UserAPI,
|
||||
VideoMajor,
|
||||
)
|
||||
from .retry import ApiCode352Error, retry_for_352
|
||||
from .scheduler import BiliBangumiSite, BilibiliSite, BililiveSite
|
||||
|
||||
|
||||
class _ProcessedText(NamedTuple):
|
||||
@@ -51,7 +51,7 @@ class _ParsedMojarPost(NamedTuple):
|
||||
|
||||
|
||||
class Bilibili(NewMessage):
|
||||
categories = {
|
||||
categories: ClassVar[dict[Category, str]] = {
|
||||
1: "一般动态",
|
||||
2: "专栏文章",
|
||||
3: "视频",
|
||||
@@ -162,7 +162,6 @@ class Bilibili(NewMessage):
|
||||
return tags
|
||||
|
||||
def _text_process(self, dynamic: str, desc: str, title: str) -> _ProcessedText:
|
||||
|
||||
# 计算视频标题和视频描述相似度
|
||||
title_similarity = 0.0 if len(title) == 0 or len(desc) == 0 else text_similarity(title, desc[: len(title)])
|
||||
if title_similarity > 0.9:
|
||||
@@ -308,7 +307,7 @@ class Bilibili(NewMessage):
|
||||
|
||||
|
||||
class Bilibililive(StatusChange):
|
||||
categories = {1: "开播提醒", 2: "标题更新提醒", 3: "下播提醒"}
|
||||
categories: ClassVar[dict[Category, str]] = {1: "开播提醒", 2: "标题更新提醒", 3: "下播提醒"}
|
||||
platform_name = "bilibili-live"
|
||||
enable_tag = False
|
||||
enabled = True
|
||||
@@ -458,7 +457,7 @@ class Bilibililive(StatusChange):
|
||||
|
||||
|
||||
class BilibiliBangumi(StatusChange):
|
||||
categories = {}
|
||||
categories: ClassVar[dict[Category, str]] = {}
|
||||
platform_name = "bilibili-bangumi"
|
||||
enable_tag = False
|
||||
enabled = True
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
import random
|
||||
from enum import Enum
|
||||
from functools import wraps
|
||||
from collections.abc import Awaitable, Callable
|
||||
from dataclasses import dataclass
|
||||
from datetime import datetime, timedelta
|
||||
from collections.abc import Callable, Awaitable
|
||||
from typing_extensions import override, assert_never
|
||||
from enum import Enum
|
||||
from functools import wraps
|
||||
import random
|
||||
from typing import TYPE_CHECKING, Generic, Literal, TypeVar
|
||||
from typing_extensions import assert_never, override
|
||||
|
||||
from strenum import StrEnum
|
||||
from nonebot.log import logger
|
||||
from httpx import URL as HttpxURL
|
||||
from nonebot.log import logger
|
||||
from strenum import StrEnum
|
||||
|
||||
from nonebot_bison.types import Target
|
||||
|
||||
from .fsm import FSM, ActionReturn, Condition, StateGraph, Transition, reset_on_exception
|
||||
from .models import DynRawPost
|
||||
from .fsm import FSM, Condition, StateGraph, Transition, ActionReturn, reset_on_exception
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .platforms import Bilibili
|
||||
@@ -115,8 +115,7 @@ class RetryAddon(Generic[TBilibili]):
|
||||
|
||||
def record_backoff_finish_time(self):
|
||||
self.backoff_finish_time = (
|
||||
datetime.now()
|
||||
+ self.backoff_timedelta * self.backoff_count**2
|
||||
datetime.now() + self.backoff_timedelta * self.backoff_count**2
|
||||
# + timedelta(seconds=random.randint(1, 60)) # jitter
|
||||
)
|
||||
logger.trace(f"set backoff finish time: {self.backoff_finish_time}")
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
from datetime import datetime, timedelta
|
||||
import json
|
||||
import random
|
||||
from typing import TYPE_CHECKING, ClassVar, TypeVar
|
||||
from typing_extensions import override
|
||||
from datetime import datetime, timedelta
|
||||
from typing import TYPE_CHECKING, TypeVar
|
||||
|
||||
from httpx import AsyncClient
|
||||
from nonebot import logger, require
|
||||
from playwright.async_api import Cookie
|
||||
|
||||
from nonebot_bison.config.db_model import Cookie as CookieModel
|
||||
from nonebot_bison.utils import Site, http_client
|
||||
|
||||
from ...utils.site import CookieClientManager
|
||||
from ...config.db_model import Cookie as CookieModel
|
||||
from nonebot_bison.utils.site import CookieClientManager
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .platforms import Bilibili
|
||||
@@ -23,7 +22,6 @@ B = TypeVar("B", bound="Bilibili")
|
||||
|
||||
|
||||
class BilibiliClientManager(CookieClientManager):
|
||||
|
||||
_default_cookie_cd = timedelta(seconds=120)
|
||||
|
||||
async def _get_cookies(self) -> list[Cookie]:
|
||||
@@ -75,7 +73,7 @@ class BilibiliClientManager(CookieClientManager):
|
||||
|
||||
class BilibiliSite(Site):
|
||||
name = "bilibili.com"
|
||||
schedule_setting = {"seconds": 60}
|
||||
schedule_setting: ClassVar[dict] = {"seconds": 60}
|
||||
schedule_type = "interval"
|
||||
client_mgr = BilibiliClientManager
|
||||
require_browser = True
|
||||
@@ -83,11 +81,11 @@ class BilibiliSite(Site):
|
||||
|
||||
class BililiveSite(Site):
|
||||
name = "live.bilibili.com"
|
||||
schedule_setting = {"seconds": 5}
|
||||
schedule_setting: ClassVar[dict] = {"seconds": 5}
|
||||
schedule_type = "interval"
|
||||
|
||||
|
||||
class BiliBangumiSite(Site):
|
||||
name = "bilibili.com/bangumi"
|
||||
schedule_setting = {"seconds": 30}
|
||||
schedule_setting: ClassVar[dict] = {"seconds": 30}
|
||||
schedule_type = "interval"
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
from typing import TypeAlias
|
||||
from functools import partial
|
||||
from datetime import timedelta
|
||||
from types import MappingProxyType
|
||||
from collections.abc import Callable
|
||||
from datetime import timedelta
|
||||
from functools import partial
|
||||
from types import MappingProxyType
|
||||
from typing import TypeAlias
|
||||
|
||||
from expiringdictx import ExpiringDict, SimpleCache
|
||||
from hishel import AsyncCacheTransport, AsyncInMemoryStorage, Controller
|
||||
from httpx import AsyncClient, AsyncHTTPTransport
|
||||
from expiringdictx import SimpleCache, ExpiringDict
|
||||
from hishel import Controller, AsyncCacheTransport, AsyncInMemoryStorage
|
||||
|
||||
from .const import DATASOURCE_URL
|
||||
from .utils import process_response
|
||||
from .models import CeobeSource, CeobeTarget, DataSourceResponse
|
||||
from .utils import process_response
|
||||
|
||||
cache_transport = AsyncCacheTransport(
|
||||
AsyncHTTPTransport(),
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from typing import Literal, TypeVar, NamedTuple
|
||||
from typing import Literal, NamedTuple, TypeVar
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
from typing import ParamSpec
|
||||
from functools import partial
|
||||
from datetime import timedelta
|
||||
from collections import defaultdict
|
||||
from datetime import timedelta
|
||||
from functools import partial
|
||||
from typing import ClassVar, ParamSpec
|
||||
|
||||
from httpx import AsyncClient
|
||||
from nonebot import logger, require
|
||||
from rapidfuzz import fuzz, process
|
||||
|
||||
from nonebot_bison.post import Post
|
||||
from nonebot_bison.platform.platform import NewMessage
|
||||
from nonebot_bison.plugin_config import plugin_config
|
||||
from nonebot_bison.types import Target, RawPost, Category
|
||||
from nonebot_bison.utils import Site, ClientManager, capture_html
|
||||
from nonebot_bison.post import Post
|
||||
from nonebot_bison.types import Category, RawPost, Target
|
||||
from nonebot_bison.utils import ClientManager, Site, capture_html
|
||||
|
||||
from ..platform import NewMessage
|
||||
from .utils import process_response
|
||||
from .const import COMB_ID_URL, COOKIES_URL, COOKIE_ID_URL
|
||||
from .exception import CeobeSnapshotSkip, CeobeSnapshotFailed
|
||||
from .cache import CeobeCache, CeobeClient, CeobeDataSourceCache
|
||||
from .models import CeobeImage, CeobeCookie, CeobeTextPic, CombIdResponse, CookiesResponse, CookieIdResponse
|
||||
from .const import COMB_ID_URL, COOKIE_ID_URL, COOKIES_URL
|
||||
from .exception import CeobeSnapshotFailed, CeobeSnapshotSkip
|
||||
from .models import CeobeCookie, CeobeImage, CeobeTextPic, CombIdResponse, CookieIdResponse, CookiesResponse
|
||||
from .utils import process_response
|
||||
|
||||
P = ParamSpec("P")
|
||||
|
||||
@@ -49,7 +49,7 @@ class CeobeCanteenSite(Site):
|
||||
name = "ceobe_canteen"
|
||||
schedule_type = "interval"
|
||||
# lwt の 推荐间隔
|
||||
schedule_setting = {"seconds": 15}
|
||||
schedule_setting: ClassVar[dict] = {"seconds": 15}
|
||||
client_mgr = CeobeCanteenClientManager
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ class CeobeCanteen(NewMessage):
|
||||
use_batch: bool = True
|
||||
default_theme: str = "ceobecanteen"
|
||||
|
||||
categories: dict[Category, str] = {1: "普通", 2: "转发"}
|
||||
categories: ClassVar[dict[Category, str]] = {1: "普通", 2: "转发"}
|
||||
|
||||
data_source_cache = CeobeDataSourceCache()
|
||||
|
||||
@@ -213,7 +213,9 @@ class CeobeCanteen(NewMessage):
|
||||
logger.debug(f"snapshot official website url: {url}")
|
||||
|
||||
# /html/body/div[1]/div[1]/div/div[1]/div[1]/div
|
||||
snapshot_selector = "html > body > div:nth-child(1) > div:nth-child(1) > div > div:nth-child(1) > div:nth-child(1) > div" # noqa: E501
|
||||
snapshot_selector = (
|
||||
"html > body > div:nth-child(1) > div:nth-child(1) > div > div:nth-child(1) > div:nth-child(1) > div"
|
||||
)
|
||||
# /html/body/div[1]/div[1]/div/div[1]/div[1]/div/div[4]/div/div/div
|
||||
calculate_selector = "html > body > div:nth-child(1) > div:nth-child(1) > div > div:nth-child(1) > div:nth-child(1) > div > div:nth-child(4) > div > div > div" # noqa: E501
|
||||
viewport = {"width": 1024, "height": 19990}
|
||||
|
||||
@@ -3,7 +3,7 @@ from nonebot import logger
|
||||
from nonebot.compat import type_validate_python
|
||||
|
||||
from .exception import CeobeResponseError
|
||||
from .models import ResponseModel, CookieIdResponse
|
||||
from .models import CookieIdResponse, ResponseModel
|
||||
|
||||
|
||||
def process_response(response: Response, parse_model: type[ResponseModel]) -> ResponseModel:
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
from typing import Any
|
||||
from typing import Any, ClassVar
|
||||
|
||||
from httpx import AsyncClient
|
||||
|
||||
from ..post import Post
|
||||
from nonebot_bison.post import Post
|
||||
from nonebot_bison.types import RawPost, Target
|
||||
from nonebot_bison.utils import anonymous_site
|
||||
|
||||
from .platform import NewMessage
|
||||
from ..utils import anonymous_site
|
||||
from ..types import Target, RawPost
|
||||
|
||||
|
||||
class FF14(NewMessage):
|
||||
categories = {}
|
||||
categories: ClassVar[dict] = {}
|
||||
platform_name = "ff14"
|
||||
name = "最终幻想XIV官方公告"
|
||||
enable_tag = False
|
||||
|
||||
@@ -1,22 +1,23 @@
|
||||
import re
|
||||
from typing import Any
|
||||
from typing import Any, ClassVar
|
||||
|
||||
from httpx import AsyncClient
|
||||
|
||||
from ..post import Post
|
||||
from ..utils import Site
|
||||
from nonebot_bison.post import Post
|
||||
from nonebot_bison.types import ApiError, Category, RawPost, Target
|
||||
from nonebot_bison.utils import Site
|
||||
|
||||
from .platform import NewMessage
|
||||
from ..types import Target, RawPost, ApiError
|
||||
|
||||
|
||||
class NcmSite(Site):
|
||||
name = "music.163.com"
|
||||
schedule_type = "interval"
|
||||
schedule_setting = {"minutes": 1}
|
||||
schedule_setting: ClassVar[dict] = {"minutes": 1}
|
||||
|
||||
|
||||
class NcmArtist(NewMessage):
|
||||
categories = {}
|
||||
categories: ClassVar[dict[Category, str]] = {}
|
||||
platform_name = "ncm-artist"
|
||||
enable_tag = False
|
||||
enabled = True
|
||||
@@ -73,7 +74,7 @@ class NcmArtist(NewMessage):
|
||||
|
||||
|
||||
class NcmRadio(NewMessage):
|
||||
categories = {}
|
||||
categories: ClassVar[dict[Category, str]] = {}
|
||||
platform_name = "ncm-radio"
|
||||
enable_tag = False
|
||||
enabled = True
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
import ssl
|
||||
import json
|
||||
import time
|
||||
import typing
|
||||
from dataclasses import dataclass
|
||||
from abc import ABC, abstractmethod
|
||||
from collections import defaultdict
|
||||
from typing import Any, TypeVar, ParamSpec
|
||||
from collections.abc import Callable, Awaitable, Collection
|
||||
from collections.abc import Awaitable, Callable, Collection
|
||||
from dataclasses import dataclass
|
||||
import json
|
||||
import ssl
|
||||
import time
|
||||
import typing
|
||||
from typing import Any, ParamSpec, TypeVar
|
||||
|
||||
import httpx
|
||||
from httpx import AsyncClient
|
||||
from nonebot.log import logger
|
||||
from nonebot_plugin_saa import PlatformTarget
|
||||
|
||||
from ..post import Post
|
||||
from ..utils import Site, ProcessContext
|
||||
from ..plugin_config import plugin_config
|
||||
from ..types import Tag, Target, RawPost, SubUnit, Category
|
||||
from nonebot_bison.plugin_config import plugin_config
|
||||
from nonebot_bison.post import Post
|
||||
from nonebot_bison.types import Category, RawPost, SubUnit, Tag, Target
|
||||
from nonebot_bison.utils import ProcessContext, Site
|
||||
|
||||
|
||||
class CategoryNotSupport(Exception):
|
||||
|
||||
@@ -1,27 +1,27 @@
|
||||
import time
|
||||
import calendar
|
||||
from typing import Any
|
||||
import time
|
||||
from typing import Any, ClassVar
|
||||
|
||||
from bs4 import BeautifulSoup as bs
|
||||
import feedparser
|
||||
from httpx import AsyncClient
|
||||
from bs4 import BeautifulSoup as bs
|
||||
|
||||
from ..post import Post
|
||||
from nonebot_bison.post import Post
|
||||
from nonebot_bison.types import Category, RawPost, Target
|
||||
from nonebot_bison.utils import text_similarity
|
||||
from nonebot_bison.utils.site import CookieClientManager, Site
|
||||
|
||||
from .platform import NewMessage
|
||||
from ..types import Target, RawPost
|
||||
from ..utils import text_similarity
|
||||
from ..utils.site import Site, CookieClientManager
|
||||
|
||||
|
||||
class RssSite(Site):
|
||||
name = "rss"
|
||||
schedule_type = "interval"
|
||||
schedule_setting = {"seconds": 30}
|
||||
schedule_setting: ClassVar[dict] = {"seconds": 30}
|
||||
client_mgr = CookieClientManager.from_name(name)
|
||||
|
||||
|
||||
class RssPost(Post):
|
||||
|
||||
async def get_plain_content(self) -> str:
|
||||
soup = bs(self.content, "html.parser")
|
||||
|
||||
@@ -38,7 +38,7 @@ class RssPost(Post):
|
||||
|
||||
|
||||
class Rss(NewMessage):
|
||||
categories = {}
|
||||
categories: ClassVar[dict[Category, str]] = {}
|
||||
enable_tag = False
|
||||
platform_name = "rss"
|
||||
name = "Rss"
|
||||
|
||||
@@ -1,21 +1,22 @@
|
||||
import re
|
||||
import json
|
||||
from typing import Any
|
||||
from datetime import datetime
|
||||
from urllib.parse import unquote
|
||||
import json
|
||||
import re
|
||||
from typing import Any, ClassVar
|
||||
from typing_extensions import override
|
||||
from urllib.parse import unquote
|
||||
|
||||
from yarl import URL
|
||||
from lxml.etree import HTML
|
||||
from httpx import AsyncClient
|
||||
from nonebot.log import logger
|
||||
from bs4 import BeautifulSoup as bs
|
||||
from httpx import AsyncClient
|
||||
from lxml.etree import HTML
|
||||
from nonebot.log import logger
|
||||
from yarl import URL
|
||||
|
||||
from nonebot_bison.post import Post
|
||||
from nonebot_bison.types import ApiError, Category, RawPost, Tag, Target
|
||||
from nonebot_bison.utils import http_client, text_fletten
|
||||
from nonebot_bison.utils.site import CookieClientManager, Site
|
||||
|
||||
from ..post import Post
|
||||
from .platform import NewMessage
|
||||
from ..utils import http_client, text_fletten
|
||||
from ..utils.site import Site, CookieClientManager
|
||||
from ..types import Tag, Target, RawPost, ApiError, Category
|
||||
|
||||
_HEADER = {
|
||||
"accept": (
|
||||
@@ -59,12 +60,12 @@ class WeiboClientManager(CookieClientManager):
|
||||
class WeiboSite(Site):
|
||||
name = "weibo.com"
|
||||
schedule_type = "interval"
|
||||
schedule_setting = {"seconds": 3}
|
||||
schedule_setting: ClassVar[dict] = {"seconds": 3}
|
||||
client_mgr = WeiboClientManager
|
||||
|
||||
|
||||
class Weibo(NewMessage):
|
||||
categories = {
|
||||
categories: ClassVar[dict[Category, str]] = {
|
||||
1: "转发",
|
||||
2: "视频",
|
||||
3: "图文",
|
||||
|
||||
Reference in New Issue
Block a user