nonebot-plugin-acgnshow 0.2.2__tar.gz → 0.2.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. {nonebot_plugin_acgnshow-0.2.2 → nonebot_plugin_acgnshow-0.2.3}/PKG-INFO +5 -2
  2. {nonebot_plugin_acgnshow-0.2.2 → nonebot_plugin_acgnshow-0.2.3}/README.md +4 -1
  3. {nonebot_plugin_acgnshow-0.2.2 → nonebot_plugin_acgnshow-0.2.3}/nonebot_plugin_acgnshow/__init__.py +1 -0
  4. {nonebot_plugin_acgnshow-0.2.2 → nonebot_plugin_acgnshow-0.2.3}/nonebot_plugin_acgnshow/acgnapis.py +8 -2
  5. {nonebot_plugin_acgnshow-0.2.2 → nonebot_plugin_acgnshow-0.2.3}/nonebot_plugin_acgnshow/acgnshower.py +12 -3
  6. {nonebot_plugin_acgnshow-0.2.2 → nonebot_plugin_acgnshow-0.2.3}/nonebot_plugin_acgnshow/config.py +3 -0
  7. {nonebot_plugin_acgnshow-0.2.2 → nonebot_plugin_acgnshow-0.2.3}/nonebot_plugin_acgnshow/res/details.html +1 -1
  8. nonebot_plugin_acgnshow-0.2.3/nonebot_plugin_acgnshow/util.py +76 -0
  9. {nonebot_plugin_acgnshow-0.2.2 → nonebot_plugin_acgnshow-0.2.3}/pyproject.toml +1 -1
  10. nonebot_plugin_acgnshow-0.2.2/nonebot_plugin_acgnshow/util.py +0 -28
  11. {nonebot_plugin_acgnshow-0.2.2 → nonebot_plugin_acgnshow-0.2.3}/LICENSE +0 -0
  12. {nonebot_plugin_acgnshow-0.2.2 → nonebot_plugin_acgnshow-0.2.3}/nonebot_plugin_acgnshow/models.py +0 -0
  13. {nonebot_plugin_acgnshow-0.2.2 → nonebot_plugin_acgnshow-0.2.3}/nonebot_plugin_acgnshow/res/SourceHanSans.otf +0 -0
  14. {nonebot_plugin_acgnshow-0.2.2 → nonebot_plugin_acgnshow-0.2.3}/nonebot_plugin_acgnshow/res/bgimage/bg1.webp +0 -0
  15. {nonebot_plugin_acgnshow-0.2.2 → nonebot_plugin_acgnshow-0.2.3}/nonebot_plugin_acgnshow/res/bgimage/bg2.webp +0 -0
  16. {nonebot_plugin_acgnshow-0.2.2 → nonebot_plugin_acgnshow-0.2.3}/nonebot_plugin_acgnshow/res/bgimage/bg3.webp +0 -0
  17. {nonebot_plugin_acgnshow-0.2.2 → nonebot_plugin_acgnshow-0.2.3}/nonebot_plugin_acgnshow/res/bgimage/bg4.webp +0 -0
  18. {nonebot_plugin_acgnshow-0.2.2 → nonebot_plugin_acgnshow-0.2.3}/nonebot_plugin_acgnshow/res/bgimage/bg5.webp +0 -0
  19. {nonebot_plugin_acgnshow-0.2.2 → nonebot_plugin_acgnshow-0.2.3}/nonebot_plugin_acgnshow/res/bgimage/bg6.webp +0 -0
  20. {nonebot_plugin_acgnshow-0.2.2 → nonebot_plugin_acgnshow-0.2.3}/nonebot_plugin_acgnshow/res/bgimage/bg7.webp +0 -0
  21. {nonebot_plugin_acgnshow-0.2.2 → nonebot_plugin_acgnshow-0.2.3}/nonebot_plugin_acgnshow/res/css/style.css +0 -0
  22. {nonebot_plugin_acgnshow-0.2.2 → nonebot_plugin_acgnshow-0.2.3}/nonebot_plugin_acgnshow/res/svg/no.svg +0 -0
  23. {nonebot_plugin_acgnshow-0.2.2 → nonebot_plugin_acgnshow-0.2.3}/nonebot_plugin_acgnshow/res/svg/yes.svg +0 -0
  24. {nonebot_plugin_acgnshow-0.2.2 → nonebot_plugin_acgnshow-0.2.3}/nonebot_plugin_acgnshow/res/template.html +0 -0
  25. {nonebot_plugin_acgnshow-0.2.2 → nonebot_plugin_acgnshow-0.2.3}/tests/__init__.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: nonebot-plugin-acgnshow
3
- Version: 0.2.2
3
+ Version: 0.2.3
4
4
  Summary: Nonebot2插件,从哔哩哔哩会员购获取简易展览数据
5
5
  Author-Email: Asankilp <asankilp@outlook.com>
6
6
  License: MIT
@@ -95,4 +95,7 @@ _✨ 从哔哩哔哩会员购获取展览简易信息 ✨_
95
95
  | 配置项 | 必填 | 默认值 | 说明 |
96
96
  | :---------------: | :--: | :----: | :----------------------------------------------------------: |
97
97
  | ACGNSHOW_PAGESIZE | 否 | 8 | 单个图片的条目数,最大为 20,条目数过大可能导致 Bot 无法发送 |
98
- | ACGNSHOW_BGIMAGE_PATH | 否 | 插件内置背景图 | 插件返回图片的背景图目录路径 |
98
+ | ACGNSHOW_BGIMAGE_PATH | 否 | 插件内置背景图 | 插件返回图片的背景图目录路径 |
99
+ | ACGNSHOW_SEND_SHOW_DETAILS_HTML | 否 | false | 是否发送展览的 HTML 详情信息图片(会员购的“活动介绍”栏目),实验性功能 |
100
+ | ACGNSHOW_SHOW_DETAILS_HTML_SCALE | 否 | 0.2 | HTML 详情信息图片的缩放比例,过大可能导致 Bot 无法发送 |
101
+ | ACGNSHOW_SHOW_DETAILS_HTML_IMG_COUNT | 否 | 2 | 每一张 HTML 详情信息图片中包含的图片个数,过大可能导致 Bot 无法发送 |
@@ -80,4 +80,7 @@ _✨ 从哔哩哔哩会员购获取展览简易信息 ✨_
80
80
  | 配置项 | 必填 | 默认值 | 说明 |
81
81
  | :---------------: | :--: | :----: | :----------------------------------------------------------: |
82
82
  | ACGNSHOW_PAGESIZE | 否 | 8 | 单个图片的条目数,最大为 20,条目数过大可能导致 Bot 无法发送 |
83
- | ACGNSHOW_BGIMAGE_PATH | 否 | 插件内置背景图 | 插件返回图片的背景图目录路径 |
83
+ | ACGNSHOW_BGIMAGE_PATH | 否 | 插件内置背景图 | 插件返回图片的背景图目录路径 |
84
+ | ACGNSHOW_SEND_SHOW_DETAILS_HTML | 否 | false | 是否发送展览的 HTML 详情信息图片(会员购的“活动介绍”栏目),实验性功能 |
85
+ | ACGNSHOW_SHOW_DETAILS_HTML_SCALE | 否 | 0.2 | HTML 详情信息图片的缩放比例,过大可能导致 Bot 无法发送 |
86
+ | ACGNSHOW_SHOW_DETAILS_HTML_IMG_COUNT | 否 | 2 | 每一张 HTML 详情信息图片中包含的图片个数,过大可能导致 Bot 无法发送 |
@@ -15,6 +15,7 @@ usage = """命令格式:
15
15
  (如北京,福建,平顶山,绍兴,香港...,或海外/全国)
16
16
 
17
17
  展览详情 <ID>
18
+ 获取指定展览ID的详细信息
18
19
  其中ID为展览列表处返回的ID
19
20
 
20
21
  示例:
@@ -110,6 +110,11 @@ def process_show_details_data_to_template(show_details_data: dict):
110
110
  else:
111
111
  guests = ""
112
112
 
113
+ desc = data["performance_desc"]["list"]
114
+ for item in desc:
115
+ if item.get("module") == "activity_content":
116
+ details_html = item.get("details", "")
117
+
113
118
  # 构建返回的字典
114
119
  item_dict = {
115
120
  "banner_url": banner_url,
@@ -123,10 +128,11 @@ def process_show_details_data_to_template(show_details_data: dict):
123
128
  "guests": guests,
124
129
  "is_refund": is_refund,
125
130
  "id_bind": id_bind,
126
- "has_eticket": has_eticket
131
+ "has_eticket": has_eticket,
132
+ "details_html": details_html
127
133
  }
128
134
 
129
- return item_dict
135
+ return [item_dict, details_html]
130
136
 
131
137
  def process_shows_data_to_template(shows_data: dict):
132
138
  showlist = []
@@ -3,7 +3,7 @@ import traceback
3
3
  from nonebot.typing import T_State
4
4
  from typing import Optional
5
5
  from .acgnapis import *
6
- from nonebot_plugin_htmlrender import template_to_pic
6
+ from nonebot_plugin_htmlrender import template_to_pic, html_to_pic
7
7
  from nonebot_plugin_alconna import on_alconna
8
8
  from nonebot_plugin_alconna.uniseg import UniMessage
9
9
  from arclet.alconna import Alconna, Args
@@ -48,9 +48,9 @@ async def get_show_details_cmd(
48
48
  if show_details["errno"] != 0: await UniMessage("发生错误").send() ; return
49
49
  try:
50
50
  show_details_data = process_show_details_data_to_template(show_details)
51
- print(show_details_data)
51
+ #print(show_details_data)
52
52
  template = {
53
- "show": show_details_data,
53
+ "show": show_details_data[0],
54
54
  "bgimage": choose_random_bgimage(),
55
55
  }
56
56
  pic = await template_to_pic(str(RES_PATH), DETAILS_TEMPLATE_NAME, template)
@@ -59,6 +59,15 @@ async def get_show_details_cmd(
59
59
  traceback.print_exc()
60
60
  return
61
61
  await UniMessage.image(raw=pic).send()
62
+ if config.acgnshow_send_show_details_html:
63
+ details_html_fragments = split_html_into_fragments(add_https_to_urls(show_details_data[1]))
64
+ details_html_groups = join_fragments_in_groups(details_html_fragments, config.acgnshow_show_details_html_img_count)
65
+ #print(details_html_groups)
66
+ #print(details_html)
67
+ for html in details_html_groups:
68
+ html_pic = await html_to_pic(html=html, device_scale_factor=config.acgnshow_show_details_html_scale)
69
+ #print(html_pic)
70
+ await UniMessage.image(raw=html_pic).send()
62
71
 
63
72
  @showcmd.handle()
64
73
  async def find_shows_cmd(
@@ -11,5 +11,8 @@ BGIMAGE_PATH = RES_PATH / "bgimage"
11
11
  class ConfigModel(BaseModel):
12
12
  acgnshow_pagesize: int = 8
13
13
  acgnshow_bgimage_path: str = BGIMAGE_PATH
14
+ acgnshow_send_show_details_html: bool = False
15
+ acgnshow_show_details_html_scale: float = 0.6
16
+ acgnshow_show_details_html_img_count: int = 2
14
17
 
15
18
  config: ConfigModel = get_plugin_config(ConfigModel)
@@ -69,7 +69,7 @@
69
69
  <div class="footer">
70
70
  <div class="designer">Designed by Asankilp?</div>
71
71
  <div class="project_name">nonebot-plugin-acgnshow</div>
72
- <div class="notice_text">本页信息仅供参考,具体内容请访问展览官方详情页,并自行检索实际信息</div>
72
+ <div class="notice_text">本页信息仅供参考,具体内容请访问哔哩哔哩会员购,并自行检索实际信息</div>
73
73
  </div>
74
74
  </div>
75
75
  </body>
@@ -0,0 +1,76 @@
1
+ import os
2
+ import re
3
+ import random
4
+ import datetime
5
+ import json
6
+ from pathlib import Path
7
+ from .config import config
8
+
9
+
10
+ def choose_random_bgimage() -> str:
11
+ """
12
+ 从背景图片文件夹中随机选择一张图片,返回图片的uri地址
13
+ """
14
+ bgpath = Path(config.acgnshow_bgimage_path)
15
+ randomfile = random.choice(os.listdir(bgpath))
16
+ randomurl = (bgpath / randomfile).as_uri()
17
+ return randomurl
18
+
19
+
20
+ def convert_timestamp(timestamp) -> str:
21
+ """
22
+ 将时间戳转换为日期格式
23
+
24
+ :param timestamp: unix 时间戳
25
+ :return: yyyy-mm-dd hh:mm:ss时间
26
+ """
27
+ return datetime.datetime.fromtimestamp(timestamp).strftime("%Y-%m-%d %H:%M:%S")
28
+
29
+ def extract_banner_url(value) -> str:
30
+ a = json.loads(value)
31
+ url = "https:"+a["banner"]["url"]
32
+ return url
33
+
34
+ def add_https_to_urls(html_content):
35
+ """
36
+ 为 HTML 内容中的缺失 https: 前缀的 URL 添加 https: 前缀
37
+
38
+ :param html_content: 包含 HTML 的字符串
39
+ :return: 修正后的 HTML 字符串
40
+ """
41
+ # 使用正则表达式查找所有以 "//" 开头的 URL
42
+ updated_html_content = re.sub(r'(?<=src=["\'])//', 'https://', html_content)
43
+ return updated_html_content
44
+
45
+ def split_html_into_fragments(html_content):
46
+ """
47
+ 将 HTML 内容按照元素分割成多个片段,并存储在列表中
48
+
49
+ :param html_content: 包含 HTML 的字符串
50
+ :return: 存储 HTML 片段的列表
51
+ """
52
+ # 使用正则表达式匹配 HTML 标签及其内容
53
+ pattern = re.compile(r'(<[^>]+>[^<]*<\/[^>]+>|<[^>]+\/>|<[^>]+>)')
54
+ fragments = pattern.findall(html_content)
55
+ return fragments
56
+
57
+ def join_fragments_in_groups(fragments, image_count=2):
58
+ """
59
+
60
+ :param fragments: 存储 HTML 片段的列表
61
+ :param image_count: 每个组包含的图片数量,默认为2
62
+ :return: 拼接后的 HTML 列表
63
+ """
64
+ grouped_html = []
65
+ count = 0
66
+ buffer = ""
67
+ for group in fragments:
68
+ buffer += group
69
+ if "img" in group:
70
+ count += 1 # 发现图片则计数器+1
71
+ if count >= image_count:
72
+ grouped_html.append(buffer)
73
+ count = 0
74
+ buffer = "" # 初始化计数器和缓冲区
75
+ grouped_html.append(buffer)# 把缓冲区剩余内容一起添加
76
+ return grouped_html
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "nonebot-plugin-acgnshow"
3
- version = "0.2.2"
3
+ version = "0.2.3"
4
4
  description = "Nonebot2插件,从哔哩哔哩会员购获取简易展览数据"
5
5
  readme = "README.md"
6
6
  requires-python = "<4.0,>=3.9"
@@ -1,28 +0,0 @@
1
- import os
2
- import random
3
- import datetime
4
- import json
5
- from pathlib import Path
6
- from .config import config
7
-
8
-
9
- def choose_random_bgimage() -> str:
10
- """
11
- 从背景图片文件夹中随机选择一张图片,返回图片的uri地址
12
- """
13
- bgpath = Path(config.acgnshow_bgimage_path)
14
- randomfile = random.choice(os.listdir(bgpath))
15
- randomurl = (bgpath / randomfile).as_uri()
16
- return randomurl
17
-
18
-
19
- def convert_timestamp(timestamp) -> str:
20
- """
21
- 将时间戳转换为日期格式
22
- """
23
- return datetime.datetime.fromtimestamp(timestamp).strftime("%Y-%m-%d %H:%M:%S")
24
-
25
- def extract_banner_url(value) -> str:
26
- a = json.loads(value)
27
- url = "https:"+a["banner"]["url"]
28
- return url