This commit is contained in:
2026-01-03 15:47:32 +08:00
parent 4bd6fc7c3e
commit af19db7082
3 changed files with 154 additions and 117 deletions
+24 -33
View File
@@ -4,7 +4,7 @@ import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties
from io import BytesIO
import base64
from datetime import datetime
from datetime import datetime,date
import calendar
def load_template(template_name):
@@ -169,37 +169,28 @@ def plot_line_chart_base64(data, x_field, y_field, title=None, reverse_x=False):
return f"data:image/png;base64,{img_base64}"
def build_calendar_items(start_date_str, data):
start_date = datetime.datetime.strptime(start_date_str, "%Y-%m-%d").date()
weekday = start_date.weekday() # 周一0 ~ 周日6
weekday = (weekday + 1) % 7 # 调整:周日=0, 周一=1 ... 周六=6
def week_to_num(week :str):
week_map = {
"": 0,
"": 1,
"": 2,
"": 3,
"": 4,
"": 5,
"": 6,
}
return week_map.get(week,None)
result = []
row = []
def compare_date_str(date_str: str) -> str:
"""
date_str 格式:YYYY-MM-DD
"""
d = datetime.strptime(date_str, "%Y-%m-%d").date()
today = date.today()
# 第一行补空
for _ in range(weekday):
row.append({"date": "", "items": [], "is_today": False})
# 排数据
for i, day in enumerate(data):
# 识别今天
is_today = (day["date"] == start_date_str)
row.append({
"date": day["day"],
"items": [day],
"is_today": is_today,
})
if len(row) == 7:
result.append(row)
row = []
# 最后一行剩余补空
if row:
while len(row) < 7:
row.append({"date": "", "items": [], "is_today": False})
result.append(row)
return result
if d < today:
return "过去"
elif d == today:
return "今天"
else:
return "将来"
+29 -2
View File
@@ -1,4 +1,6 @@
# pyright: reportArgumentType=false
from datetime import datetime
from typing import Dict, Any, Optional, List, Union
@@ -7,7 +9,7 @@ from astrbot.api import AstrBotConfig
from .request import APIClient
from .aiosqlite import AsyncSQLite
from .function_basic import load_template,gold_to_string,build_calendar_items
from .function_basic import load_template,gold_to_string,week_to_num,compare_date_str
class JX3Service:
def __init__(self, api_config, config:AstrBotConfig):
@@ -165,10 +167,34 @@ class JX3Service:
# 3. 处理返回数据
try:
return_data["data"]["items"] = build_calendar_items(data["today"]["date"],data["data"])
items = []
num_richang = week_to_num(data["data"][0]["week"])
# 空白数据
for _ in range(num_richang):
items.append({
"en": False,
"compare": "",
"date": "",
"war": "",
"battle": ""
})
# 真实数据
for m in data["data"]:
items.append({
"en": True,
"compare": compare_date_str(m.get("date", "")),
"date": m.get("date", ""),
"war": m.get("war", ""),
"battle": m.get("battle", "")
})
return_data["data"]["items"] = items
return_data["data"]["today"] = data["today"]
except Exception as e:
logger.error(f"richang 数据处理时出错: {e}")
return_data["msg"] = "处理接口返回信息时出错"
# 加载模板
try:
return_data["temp"] = load_template("richangyuche.html")
@@ -176,6 +202,7 @@ class JX3Service:
logger.error(f"加载模板失败: {e}")
return_data["msg"] = "系统错误:模板文件不存在"
return_data["code"] = 200
return return_data
+101 -82
View File
@@ -1,93 +1,112 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>未来战场日程表</title>
<style>
body {
margin: 0; padding: 20px;
background: #f5f7fb; color: #1f2333;
font-family: "Microsoft YaHei", Arial, sans-serif;
}
.calendar {
width: 100%;
border-collapse: collapse;
table-layout: fixed;
}
.calendar th {
background: #4f7cff;
color: white;
padding: 10px 0;
font-size: 18px;
}
.calendar td {
border: 1px solid #dce1eb;
vertical-align: top;
padding: 8px;
background: #ffffff;
}
.today {
background: #fff6d1;
border: 2px solid #ffb100;
}
.date-num {
font-weight: bold;
font-size: 16px;
margin-bottom: 4px;
display: block;
}
.item-block {
font-size: 12px;
margin-bottom: 6px;
padding: 4px;
border-radius: 4px;
background: #f0f3fa;
}
.item-block span {
font-weight: bold;
}
</style>
<meta charset="UTF-8">
<title>日常预测</title>
<style>
body {
font-family: 'Microsoft YaHei', Arial, sans-serif;
background: #f1f2f6;
margin: 0;
padding: 20px;
}
.container {
max-width: 1100px;
margin: 0 auto;
}
h1 {
font-size: 32px;
margin-bottom: 25px;
color: #222;
font-weight: 800;
text-align: center;
}
/* ====== 日历网格 ====== */
.calendar {
display: grid;
grid-template-columns: repeat(7, 1fr);
gap: 14px;
}
/* 表头 */
.week {
text-align: center;
font-size: 18px;
font-weight: 700;
color: #555;
}
/* 卡片基础 */
.card {
min-height: 120px;
border-radius: 12px;
padding: 12px;
box-sizing: border-box;
background: transparent;
}
/* 状态样式 */
.card.past {
background: #e5e5e5;
color: #666;
}
.card.today {
background: #3b82f6;
color: #fff;
}
.card.future {
background: #ffffff;
color: #333;
border: 1px solid #ddd;
}
/* 内容 */
.date {
font-weight: 700;
margin-bottom: 8px;
}
.line {
font-size: 16px;
margin-top: 6px;
}
</style>
</head>
<body>
<h1 style="margin-bottom:20px;">未来战场日程表</h1>
<div class="container">
<h1>日常预测</h1>
<table class="calendar">
<thead>
<tr>
<th></th><th></th><th></th><th></th><th></th><th></th><th></th>
</tr>
</thead>
<tbody>
{% for week in items %}
<tr>
{% for day in week %}
{% if day.date %}
<td class="{% if day.is_today %}today{% endif %}">
<span class="date-num">{{ day.date }}</span>
{% for obj in day.items %}
<div class="item-block">
<div><span>战场:</span>{{ obj.battle }}</div>
<div><span>战役:</span>{{ obj.war }}</div>
<div><span>运车:</span>{{ obj.orecar }}</div>
<div><span>门派:</span>{{ obj.school }}</div>
<div><span>救援:</span>{{ obj.rescue }}</div>
{% if obj.card %}
<div><span>卡牌:</span>{{ obj.card | join('、') }}</div>
{% endif %}
</div>
{% endfor %}
</td>
{% else %}
<td style="background:#f0f2f7;"></td>
{% endif %}
<div class="calendar">
<!-- 星期头 -->
{% for w in ["周一","周二","周三","周四","周五","周六","周日"] %}
<div class="week">{{ w }}</div>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
<!-- 日程卡片 -->
{% for m in items %}
<div class="
card
{% if m.compare == '过去' %}past{% endif %}
{% if m.compare == '今天' %}today{% endif %}
{% if m.compare == '将来' %}future{% endif %}
">
{% if m.en %}
<div class="date">{{ m.date }}</div>
<div class="line">日常:{{ m.war }}</div>
<div class="line">战场:{{ m.battle }}</div>
{% endif %}
</div>
{% endfor %}
</div>
</div>
</body>
</html>