From f417f829cce834d09e0572a1849a26cddc183faf Mon Sep 17 00:00:00 2001 From: EillesWan Date: Wed, 22 Jan 2025 12:15:07 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=98=8A=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E7=BB=93=E6=9E=84=EF=BC=8C=E7=BB=9F=E4=B8=80=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E4=B8=BB=E9=A2=98=EF=BC=8C=E4=BC=98=E5=8C=96=E6=80=BB?= =?UTF-8?q?=E4=BD=93=E8=B4=A8=E6=84=9F=EF=BC=8C=E9=9D=9E=E5=B8=B8=E5=AE=8C?= =?UTF-8?q?=E7=BE=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/settings.json | 4 + nonebot_plugin_acgnshow/acgnapis.py | 59 ++++++++------- nonebot_plugin_acgnshow/acgnshower.py | 33 +++++--- nonebot_plugin_acgnshow/config.py | 3 +- nonebot_plugin_acgnshow/res/css/detail.css | 80 ++++++++++++++++++++ nonebot_plugin_acgnshow/res/css/style.css | 88 ++++++---------------- nonebot_plugin_acgnshow/res/details.html | 1 + nonebot_plugin_acgnshow/util.py | 59 +++++++++++---- 8 files changed, 209 insertions(+), 118 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 nonebot_plugin_acgnshow/res/css/detail.css diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..c0e8e39 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "python.analysis.autoImportCompletions": true, + "python.analysis.typeCheckingMode": "standard" +} \ No newline at end of file diff --git a/nonebot_plugin_acgnshow/acgnapis.py b/nonebot_plugin_acgnshow/acgnapis.py index 304c345..fd9b01c 100644 --- a/nonebot_plugin_acgnshow/acgnapis.py +++ b/nonebot_plugin_acgnshow/acgnapis.py @@ -58,35 +58,35 @@ async def get_shows_data(region_id: int, page=1, pagesize=20): shows_data = await resp.json() return shows_data + async def get_show_details(show_id: int): - param = { - "id": show_id, - "project_id": show_id, - "requestSource": "neul-next" - } + param = {"id": show_id, "project_id": show_id, "requestSource": "neul-next"} async with ClientSession() as session: - async with session.get(SHOW_DETAILS_API_ROOT, headers=HEADERS, params=param) as resp: + async with session.get( + SHOW_DETAILS_API_ROOT, headers=HEADERS, params=param + ) as resp: show_details_data = await resp.json() return show_details_data -def process_show_details_data_to_template(show_details_data: dict): + +def process_show_details_data_to_template(show_details_data: dict) -> tuple: data = show_details_data["data"] - - banner_url = "https:"+data["banner"] + + banner_url = "https:" + data["banner"] # banner_url = extract_banner_url(data["performance_image"]) - + # 提取事件基本信息 name = data["name"] start_time = convert_timestamp(data["start_time"]) end_time = convert_timestamp(data["end_time"]) - + # 提取场馆信息 venue_name = data["venue_info"]["name"] venue_detail = data["venue_info"]["address_detail"] - + # 提取主办方信息 organizer = data["merchant"]["company"] - + # 提取实名制,退票等信息 is_refund = data["is_refund"] id_bind = data["id_bind"] @@ -96,21 +96,24 @@ def process_show_details_data_to_template(show_details_data: dict): ticket_info = [] for screen in data.get("screen_list", []): for ticket in screen.get("ticket_list", []): - ticket_info.append({ - "description": ticket.get("desc", ""), - "price": ticket.get("price", 0), - "sale_start": convert_timestamp(ticket.get("saleStart", 0)), - "sale_end": convert_timestamp(ticket.get("saleEnd", 0)), - "status": ticket.get("sale_flag", {}).get("display_name", ""), - "screen_name": ticket.get("screen_name") - }) + ticket_info.append( + { + "description": ticket.get("desc", ""), + "price": ticket.get("price", 0), + "sale_start": convert_timestamp(ticket.get("saleStart", 0)), + "sale_end": convert_timestamp(ticket.get("saleEnd", 0)), + "status": ticket.get("sale_flag", {}).get("display_name", ""), + "screen_name": ticket.get("screen_name"), + } + ) guests_list = data["guests"] if guests_list != None: guests = "、".join(n["name"] for n in guests_list) else: guests = "" - + desc = data["performance_desc"]["list"] + details_html = "" # 可能未绑定 for item in desc: if item.get("module") == "activity_content": details_html = item.get("details", "") @@ -129,12 +132,13 @@ def process_show_details_data_to_template(show_details_data: dict): "is_refund": is_refund, "id_bind": id_bind, "has_eticket": has_eticket, - "details_html": details_html + "details_html": details_html, } - - return [item_dict, details_html] -def process_shows_data_to_template(shows_data: dict): + return item_dict, details_html + + +def process_shows_data_to_template(shows_data: dict) -> tuple: showlist = [] data = shows_data["data"] page = data["page"] @@ -184,4 +188,5 @@ def process_shows_data_to_template(shows_data: dict): "total_pages": total_pages, "total_results": total_results, } - return [showlist, global_data_dict] + # return (sorted(showlist, key=lambda x: x["start_time"]), global_data_dict) + return showlist, global_data_dict diff --git a/nonebot_plugin_acgnshow/acgnshower.py b/nonebot_plugin_acgnshow/acgnshower.py index e1f379c..f6f3f9f 100644 --- a/nonebot_plugin_acgnshow/acgnshower.py +++ b/nonebot_plugin_acgnshow/acgnshower.py @@ -39,15 +39,19 @@ showcmd_details.shortcut( }, ) + @showcmd_details.handle() -async def get_show_details_cmd( - id: Optional[int] = None -): +async def get_show_details_cmd(id: Optional[int] = None): + if not id: + await UniMessage("请输入展览ID").send() + return show_details = await get_show_details(id) - if show_details["errno"] != 0: await UniMessage("发生错误").send() ; return + if show_details["errno"] != 0: + await UniMessage("发生{}号错误".format(show_details["errno"])).send() + return try: show_details_data = process_show_details_data_to_template(show_details) - #print(show_details_data) + # print(show_details_data) template = { "show": show_details_data[0], "bgimage": choose_random_bgimage(), @@ -59,15 +63,22 @@ async def get_show_details_cmd( return await UniMessage.image(raw=pic).send() if config.acgnshow_send_show_details_html: - details_html_fragments = split_html_into_fragments(add_https_to_urls(show_details_data[1])) - details_html_groups = join_fragments_in_groups(details_html_fragments, config.acgnshow_show_details_html_img_count) - #print(details_html_groups) - #print(details_html) + details_html_fragments = split_html_into_fragments( + add_https_to_urls(show_details_data[1]) + ) + details_html_groups = join_fragments_in_groups( + details_html_fragments, config.acgnshow_show_details_html_img_count + ) + # print(details_html_groups) + # print(details_html) for html in details_html_groups: - html_pic = await html_to_pic(html=html, device_scale_factor=config.acgnshow_show_details_html_scale) - #print(html_pic) + html_pic = await html_to_pic( + html=html, device_scale_factor=config.acgnshow_show_details_html_scale + ) + # print(html_pic) await UniMessage.image(raw=html_pic).send() + @showcmd.handle() async def find_shows_cmd( region: Optional[str] = None, diff --git a/nonebot_plugin_acgnshow/config.py b/nonebot_plugin_acgnshow/config.py index a46b781..5adb332 100644 --- a/nonebot_plugin_acgnshow/config.py +++ b/nonebot_plugin_acgnshow/config.py @@ -10,9 +10,10 @@ BGIMAGE_PATH = RES_PATH / "bgimage" class ConfigModel(BaseModel): acgnshow_pagesize: int = 10 - acgnshow_bgimage_path: str = BGIMAGE_PATH + acgnshow_bgimage_path: str = BGIMAGE_PATH.resolve().as_posix() acgnshow_send_show_details_html: bool = False acgnshow_show_details_html_scale: float = 0.6 acgnshow_show_details_html_img_count: int = 2 + config: ConfigModel = get_plugin_config(ConfigModel) diff --git a/nonebot_plugin_acgnshow/res/css/detail.css b/nonebot_plugin_acgnshow/res/css/detail.css new file mode 100644 index 0000000..d117554 --- /dev/null +++ b/nonebot_plugin_acgnshow/res/css/detail.css @@ -0,0 +1,80 @@ + +.detail_content { + display: flex; + border: 1px solid rgba(0, 0, 0, 0.25); + height: 201px; + margin-bottom: 10px; + padding: 5px; + position: relative; + box-sizing: border-box; + background-color: rgba(183, 207, 255, 0.5); /* 半透明白色背景 */ +} + +.vector_icon { + width: 20px; + height: 20px; + vertical-align: bottom; + margin-left: 5px; +} + +.banner { + margin-bottom: 15px; + border: 2px solid rgba(0, 0, 0, 0.45); /* 为 banner 添加边框 */ + display: flex; + justify-content: center; /* 居中对齐图片 */ + align-items: center; /* 垂直居中对齐图片 */ +} + +.banner img { + width: 450px; + height: 253px; +} + +.details .ticket_box { + display: inline-block; /* 根据内容的宽度自动调整 */ + border: rgba(0, 0, 0, 0.15); + background-color: rgba(109, 146, 220, 0.15); /* 半透明蓝白色背景 */ + /* border-radius: 15px; 圆角半径 谁允许你圆了 */ + padding: 15px; /* 内边距 */ + box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); /* 添加阴影以增强视觉效果 */ + text-align: center; /* 内容水平居中 */ + width: auto; /* 根据内容宽度自动调整 */ + font-size: 10px; +} + +.details { + flex: 1; + padding-left: 10px; + display: flex; + flex-direction: column; + position: relative; /* 使子元素绝对定位相对于这个父元素 */ + font-size: 12px; +} + +.details .title { + font-weight: bold; /* 加粗字体 */ + margin-bottom: 5px; + font-size: 20px; +} + + +.details .status { + position: absolute; + display: flex; + bottom: 5px; +} + +.details .start-time { + position: absolute; + bottom: 20px; /* 与end-time有一定的高度差异 */ + right: 5px; + font-size: 11px; +} + +.details .end-time { + position: absolute; + bottom: 5px; + right: 5px; + font-size: 11px; +} + diff --git a/nonebot_plugin_acgnshow/res/css/style.css b/nonebot_plugin_acgnshow/res/css/style.css index c004ca9..eb8a006 100644 --- a/nonebot_plugin_acgnshow/res/css/style.css +++ b/nonebot_plugin_acgnshow/res/css/style.css @@ -22,13 +22,13 @@ body { width: 98%; margin: 1%; padding: 10px; - border: 1px solid #fff; + border: 1px solid rgba(255, 255, 255, 0.5); box-sizing: border-box; - background-color: rgba(255, 255, 255, 0.8); /* 半透明白色背景 */ + background-color: rgba(255, 255, 255, 0.5); /* 半透明白色背景 */ } .header { - border: 1px solid black; + border: 1px solid rgba(0, 0, 0, 0.45); padding: 5px; margin-bottom: 10px; text-align: center; @@ -38,21 +38,12 @@ body { .content { display: flex; - border: 1px solid black; - margin-bottom: 10px; - padding: 5px; - position: relative; - box-sizing: border-box; -} - -.detail_content { - display: flex; - border: 1px solid black; - height: 201px; + border: 1px solid rgba(0, 0, 0, 0.5); margin-bottom: 10px; padding: 5px; position: relative; box-sizing: border-box; + background-color: rgba(183, 207, 255, 0.25); /* 半透明白色背景 */ } .image { @@ -63,48 +54,19 @@ body { box-sizing: border-box; } -.vector_icon { - width: 20px; - height: 20px; - vertical-align: bottom; - margin-left: 5px; -} - -.banner { - margin-bottom: 15px; - border: 2px solid #000; /* 为 banner 添加边框 */ - display: flex; - justify-content: center; /* 居中对齐图片 */ - align-items: center; /* 垂直居中对齐图片 */ -} - -.banner img { - width: 450px; - height: 253px; -} - -.details .ticket_box { - display: inline-block; /* 根据内容的宽度自动调整 */ - background-color: rgba(255, 255, 255, 0.1); /* 半透明白色背景 */ - border-radius: 15px; /* 圆角半径 */ - padding: 20px; /* 内边距 */ - box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); /* 添加阴影以增强视觉效果 */ - text-align: center; /* 内容水平居中 */ - width: auto; /* 根据内容宽度自动调整 */ -} - .details { flex: 1; padding-left: 10px; display: flex; flex-direction: column; position: relative; /* 使子元素绝对定位相对于这个父元素 */ - font-size: 10px; + font-size: 12px; } .details .title { font-weight: bold; /* 加粗字体 */ margin-bottom: 5px; + font-size: 13px; } .details .venue_name, @@ -116,14 +78,14 @@ body { .details .sale_flag { color: red; position: absolute; - top: 5px; + top: 15px; right: 5px; } .details .id { color: black; position: absolute; - top: 20px; + top: 30px; right: 5px; } @@ -135,33 +97,31 @@ body { left: 5px; } -.details .status { - position: absolute; - display: flex; - bottom: 5px; -} - .details .wish { color: gray; position: absolute; bottom: 5px; - left: 80px; /* 适当调整以避免与price重叠 */ + left: 90px; /* 适当调整以避免与price重叠 */ + font-size: 10px; } .details .start-time { position: absolute; bottom: 20px; /* 与end-time有一定的高度差异 */ right: 5px; + font-size: 10px; } .details .end-time { position: absolute; bottom: 5px; right: 5px; + font-size: 10px; } .footer { - border: 1px solid black; + margin-top: 15px; + border: 1px solid rgb(0, 0, 0, 0.25); flex: 1; padding-left: 10px; display: flex; @@ -179,30 +139,30 @@ body { margin: 10px 0; } -.footer .pages, -.footer .total_results { +.footer .total_results, +.footer .pages { position: absolute; font-size: 10px; } -.footer .pages { - bottom: 5px; - right: 5px; -} - .footer .total_results { bottom: 5px; left: 5px; } +.footer .pages { + bottom: 5px; + right: 5px; +} + .footer .project_name { font-size: 10px; text-align: center; - color: rgb(50, 227, 227); + color: rgb(34, 154, 154); } .footer .notice_text { font-size: 8px; text-align: center; - color: slateblue; + color: rgb(81, 69, 159); } diff --git a/nonebot_plugin_acgnshow/res/details.html b/nonebot_plugin_acgnshow/res/details.html index 2b8dae9..cf7f0d9 100644 --- a/nonebot_plugin_acgnshow/res/details.html +++ b/nonebot_plugin_acgnshow/res/details.html @@ -5,6 +5,7 @@ Show Details +