From e0efc1dabb15b996c91ccceb39f09f3f2bc4fb20 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Wed, 29 May 2024 14:36:28 +0800 Subject: [PATCH] add DailyWord --- package.json | 9 ++ plugins/crossseed/__init__.py | 3 +- plugins/dailyword/__init__.py | 250 +++++++++++++++++++++++++++++++ plugins/trendingshow/__init__.py | 2 +- 4 files changed, 262 insertions(+), 2 deletions(-) create mode 100644 plugins/dailyword/__init__.py diff --git a/package.json b/package.json index fe4c4fd..47ceb39 100644 --- a/package.json +++ b/package.json @@ -764,5 +764,14 @@ "icon": "Dsphoto_A.png", "author": "jxxghp", "level": 1 + }, + "DailyWord": { + "name": "每日一言", + "description": "在仪表板中显示每日一言卡片。", + "labels": "仪表板", + "version": "1.0", + "icon": "Calibre_B.png", + "author": "jxxghp", + "level": 1 } } diff --git a/plugins/crossseed/__init__.py b/plugins/crossseed/__init__.py index 1ef301a..82fb138 100644 --- a/plugins/crossseed/__init__.py +++ b/plugins/crossseed/__init__.py @@ -294,7 +294,8 @@ class CrossSeed(_PluginBase): for site_key in self._token.strip().split("\n"): site_key_arr = re.split(r"[\s::]+", site_key.strip()) site_name = site_key_arr[0] - site_name_key_map[site_name] = site_key_arr[1] + if len(site_key_arr) > 1: + site_name_key_map[site_name] = site_key_arr[1] if len(site_key_arr) > 2: if str.isdigit(site_key_arr[2]): site_name_gap_map[site_name] = int(site_key_arr[2]) diff --git a/plugins/dailyword/__init__.py b/plugins/dailyword/__init__.py new file mode 100644 index 0000000..e0c9af8 --- /dev/null +++ b/plugins/dailyword/__init__.py @@ -0,0 +1,250 @@ +from typing import List, Tuple, Dict, Any, Optional + +from cachetools import TTLCache, cached + +from app.plugins import _PluginBase +from app.utils.http import RequestUtils + + +class DailyWord(_PluginBase): + # 插件名称 + plugin_name = "每日一言" + # 插件描述 + plugin_desc = "在仪表板中显示每日一言卡片。" + # 插件图标 + plugin_icon = "Calibre_B.png" + # 插件版本 + plugin_version = "1.0" + # 插件作者 + plugin_author = "jxxghp" + # 作者主页 + author_url = "https://github.com/jxxghp" + # 插件配置项ID前缀 + plugin_config_prefix = "dailyowrd_" + # 加载顺序 + plugin_order = 99 + # 可使用的用户级别 + auth_level = 1 + + _enable: bool = False + _size: str = "mini" + + def init_plugin(self, config: dict = None): + self._enable = config.get("enable") + self._size = config.get("size") + + @staticmethod + def get_command() -> List[Dict[str, Any]]: + pass + + def get_api(self) -> List[Dict[str, Any]]: + pass + + def get_form(self) -> Tuple[List[dict], Dict[str, Any]]: + return [ + { + 'component': 'VForm', + 'content': [ + { + 'component': 'VRow', + 'content': [ + { + 'component': 'VCol', + 'props': { + 'cols': 12, + 'md': 6 + }, + 'content': [ + { + 'component': 'VSwitch', + 'props': { + 'model': 'enable', + 'label': '启用插件', + } + } + ] + } + ] + }, + { + 'component': 'VRow', + 'content': [ + { + 'component': 'VCol', + 'props': { + 'cols': 12, + 'md': 4 + }, + 'content': [ + { + 'component': 'VSelect', + 'props': { + 'model': 'size', + 'label': '组件规格', + 'items': [ + {"title": "迷你", "value": "mini"}, + {"title": "小型", "value": "small"}, + {"title": "中型", "value": "medium"}, + {"title": "大型", "value": "large"} + ] + } + } + ] + } + ] + } + ] + } + ], { + "enable": self._enable, + "size": self._size + } + + def get_page(self) -> List[dict]: + pass + + def get_dashboard_meta(self) -> Optional[List[Dict[str, str]]]: + """ + 获取插件仪表盘元信息 + 返回示例: + [{ + "key": "dashboard1", // 仪表盘的key,在当前插件范围唯一 + "name": "仪表盘1" // 仪表盘的名称 + }, { + "key": "dashboard2", + "name": "仪表盘2" + }] + """ + return [{ + "key": "dailyword_dashboard", + "name": "每日一言" + }] + + @cached(cache=TTLCache(maxsize=1, ttl=43200)) + def __get_youngam(self) -> Optional[dict]: + """ + 获取每日一言,缓存12小时 + """ + res = RequestUtils().get_res("https://apier.youngam.cn/essay/one") + if res: + datalist = res.json().get("dataList") + return datalist[0] if datalist else {} + return {} + + def get_dashboard(self, key: str = None, **kwargs) -> Optional[Tuple[Dict[str, Any], Dict[str, Any], List[dict]]]: + """ + 获取插件仪表盘页面,需要返回:1、仪表板col配置字典;2、全局配置(自动刷新等);3、仪表板页面元素配置json(含数据) + 1、col配置参考: + { + "cols": 12, "md": 6 + } + 2、全局配置参考: + { + "refresh": 10 // 自动刷新时间,单位秒 + } + 3、页面配置使用Vuetify组件拼装,参考:https://vuetifyjs.com/ + """ + # 列配置 + if self._size == "mini": + cols = { + "cols": 12, + "md": 4 + } + height = 160 + elif self._size == "small": + cols = { + "cols": 12, + "md": 6 + } + height = 262 + elif self._size == "medium": + cols = { + "cols": 12, + "md": 8 + } + height = 335 + else: + cols = { + "cols": 12, + "md": 12 + } + height = 500 + # 全局配置 + attrs = { + "border": False + } + # 获取流行越势数据 + data = self.__get_youngam() + if not data: + elements = [ + { + 'component': 'VCard', + 'content': [ + { + 'component': 'VCardText', + 'props': { + 'class': 'text-center', + }, + 'content': [ + { + 'component': 'span', + 'props': { + 'class': 'text-h6' + }, + 'text': '无数据' + } + ] + } + ] + } + ] + else: + elements = [ + { + 'component': 'VCard', + 'props': { + 'class': 'p-0' + }, + 'content': [ + { + 'component': 'VImg', + 'props': { + 'src': data.get('src'), + 'cover': True, + 'height': height + }, + 'content': [ + { + 'component': 'VCardText', + 'props': { + 'class': 'w-full flex flex-col flex-wrap justify-end align-left text-white absolute bottom-0 pa-4', + }, + 'content': [ + { + 'component': 'h1', + 'props': { + 'class': 'mb-1 text-white text-shadow text-xl line-clamp-4 overflow-hidden text-ellipsis ...' + }, + 'html': data.get('text'), + }, + { + 'component': 'span', + 'props': { + 'class': 'text-right text-shadow line-clamp-2 overflow-hidden text-ellipsis ...' + }, + 'text': f"{data.get('year')}年{data.get('month')}月{data.get('day')}日", + } + ] + } + ] + } + ] + }] + + return cols, attrs, elements + + def get_state(self) -> bool: + return self._enable + + def stop_service(self): + pass diff --git a/plugins/trendingshow/__init__.py b/plugins/trendingshow/__init__.py index a7e7df4..3f594ef 100644 --- a/plugins/trendingshow/__init__.py +++ b/plugins/trendingshow/__init__.py @@ -197,7 +197,7 @@ class TrendingShow(_PluginBase): { 'component': 'VCardText', 'props': { - 'class': 'w-full flex flex-col flex-wrap justify-end align-left text-white absolute bottom-0 cursor-pointer pa-4', + 'class': 'w-full flex flex-col flex-wrap justify-end align-left text-white absolute bottom-0 pa-4', }, 'content': [ {