Cateon Huo 9e5dcb3912
实现 Post.content 相关扩展协议 (#553)
*  `post` 新增 `get_content()` 方法

* 🚨 make linter happy

* 💄 auto fix by pre-commit hooks

* 🐛 fix: 调整函数使用

* 💄 auto fix by pre-commit hooks

*  转用函数处理文本

* 💄 auto fix by pre-commit hooks

* 🔨 使用`Dict`存储`content_handlers`

* 💄 auto fix by pre-commit hooks

* 🎨 fix

* :arts: 简化函数使用

* 🐛 移除`Theme`的过时参数

* 🗑️ 复用 `self.plain_content`

* 💄 auto fix by pre-commit hooks

*  注册式装饰器写法

* 💄 auto fix by pre-commit hooks

* 🐛 fix

* 💄 auto fix by pre-commit hooks

* :feat: 通用纯文本处理函数

* 💄 auto fix by pre-commit hooks

* :downgrade: 复用`==`处理标题

* 🎨 简化(?)写法

*  测试修复

* ♻️ via ContentSupport extensions

* 🐛 fix test

* 💄 auto fix by pre-commit hooks

* 🐛 for clean text

* 🐛 fix

* 💄 auto fix by pre-commit hooks

* fix: for xml

* 💄 auto fix by pre-commit hooks

* chore: art

* 💄 auto fix by pre-commit hooks

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-08-04 18:39:12 +08:00

48 lines
1.4 KiB
Python

from typing import Any
from httpx import AsyncClient
from ..post import Post
from .platform import NewMessage
from ..utils import anonymous_site
from ..types import Target, RawPost
class FF14(NewMessage):
categories = {}
platform_name = "ff14"
name = "最终幻想XIV官方公告"
enable_tag = False
enabled = True
is_common = False
scheduler_class = "ff14"
site = anonymous_site("interval", {"seconds": 60})
has_target = False
@classmethod
async def get_target_name(cls, client: AsyncClient, target: Target) -> str | None:
return "最终幻想XIV官方公告"
async def get_sub_list(self, _) -> list[RawPost]:
client = await self.ctx.get_client()
raw_data = await client.get(
"https://cqnews.web.sdo.com/api/news/newsList?gameCode=ff&CategoryCode=5309,5310,5311,5312,5313&pageIndex=0&pageSize=5"
)
return raw_data.json()["Data"]
def get_id(self, post: RawPost) -> Any:
"""用发布时间当作 ID
因为有时候官方会直接编辑以前的文章内容
"""
return post["PublishDate"]
def get_date(self, _: RawPost) -> None:
return None
async def parse(self, raw_post: RawPost) -> Post:
title = raw_post["Title"]
text = raw_post["Summary"]
url = raw_post["Author"]
return Post(self, content=text, title=title, url=url, nickname="最终幻想XIV官方公告")