-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c335905
commit 2b9fbd8
Showing
3 changed files
with
272 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,90 @@ | ||
from jinja2 import Template | ||
from pathlib import Path | ||
|
||
from src.tools.config import Config | ||
from src.tools.basic.msg import PROMPT | ||
from src.tools.basic.data_server import server_mapping | ||
from src.tools.utils.request import get_api | ||
from src.tools.utils.path import ASSETS, CACHE, VIEWS | ||
from src.tools.utils.common import getCurrentTime, convert_time | ||
from src.tools.file import read, write | ||
from src.tools.generate import get_uuid, generate | ||
|
||
import json | ||
|
||
token = Config.jx3.api.token | ||
bot_name = Config.bot_basic.bot_name_argument | ||
|
||
template_jinjia = """ | ||
<tr> | ||
<td class="short-column">{{ date }}</td> | ||
<td class="short-column">{{ _7881 }}</td> | ||
<td class="short-column">{{ wbl }}</td> | ||
<td class="short-column">{{ dd373 }}</td> | ||
<td class="short-column">{{ _5173 }}</td> | ||
<td class="short-column">{{ uu898 }}</td> | ||
</tr>""" | ||
|
||
types = { | ||
"7881": "_7881", | ||
"WBL": "wbl", | ||
"DD373": "dd373", | ||
"5173": "_5173", | ||
"UU898": "uu898" | ||
} | ||
|
||
async def demon_(server: str = None, group_id: str = None): # 金价 <服务器> | ||
server = server_mapping(server, group_id) | ||
if not server: | ||
goal_server = server_mapping(server, group_id) | ||
if not goal_server: | ||
return [PROMPT.ServerNotExist] | ||
final_url = f"{Config.jx3.api.url}/view/trade/demon?robot={bot_name}&server={server}&chrome=1&token={token}" | ||
data = await get_api(final_url) | ||
if data["code"] == 400: | ||
return ["服务器名输入错误,请检查后重试~"] | ||
return data["data"]["url"] | ||
data = await get_api("https://spider2.jx3box.com/api/spider/gold/trend") | ||
server_data = data[goal_server] | ||
rows = [] | ||
dates = [] | ||
date_to_data = {} | ||
|
||
for platform_data in data[goal_server]["7881"]: | ||
# 只拿日期,平台不影响 | ||
dates.append(platform_data["date"]) | ||
|
||
platform_to_averages = {param_name: [] for param_name in types.values()} | ||
|
||
for platform_name, param_name in types.items(): | ||
if platform_name in server_data: | ||
platform_data = server_data[platform_name] | ||
for daily_data in platform_data: | ||
date = daily_data["date"] | ||
if date not in date_to_data: | ||
date_to_data[date] = {} | ||
date_to_data[date][param_name] = round(daily_data["average"], 2) | ||
platform_to_averages[param_name].append(int(daily_data["average"])) | ||
|
||
sorted_dates = sorted(date_to_data.keys(), reverse=True) | ||
recent_dates = sorted_dates[:7] | ||
for date in recent_dates: | ||
row_data = date_to_data[date] | ||
row_data.update({"date": date}) | ||
rows.append(row_data) | ||
|
||
tables = [] | ||
for row in rows: | ||
tables.append(Template(template_jinjia).render(**row)) | ||
|
||
input_data = { | ||
"custom_font": ASSETS + "/font/custom.ttf", | ||
"tablecontent": "\n".join(tables), | ||
"server": server, | ||
"app_time": convert_time(getCurrentTime(), "%H:%M:%S"), | ||
"saohua": "严禁将蓉蓉机器人与音卡共存,一经发现永久封禁!蓉蓉是抄袭音卡的劣质机器人!", | ||
"platforms": json.dumps(list(types), ensure_ascii=False).replace("WBL", "万宝楼"), | ||
"dates": json.dumps(dates, ensure_ascii=False), | ||
"app_name": "金币价格" | ||
} | ||
for platform in types: | ||
input_data[types[platform]] = json.dumps(platform_to_averages[types[platform]], ensure_ascii=False) | ||
|
||
html = Template(read(VIEWS + "/jx3/trade/gold.html")).render(**input_data) | ||
final_html = CACHE + "/" + get_uuid() + ".html" | ||
write(final_html, html) | ||
final_path = await generate(final_html, False, "table", False) | ||
return Path(final_path).as_uri() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
<!DOCTYPE html> | ||
<html lang="zh-CN"> | ||
|
||
<head> | ||
<!-- | ||
该代码协议与Inkar Suki仓库协议相同。 | ||
禁止帝君和兔兔使用。 | ||
禁止任何人商用。 | ||
欢迎借鉴或用于开源项目。 | ||
——HornCopper | ||
--> | ||
<style> | ||
table { | ||
width: 800px; | ||
border-collapse: separate; | ||
border-spacing: 0; | ||
border: 1px solid #000; | ||
} | ||
|
||
th { | ||
background-color: #333; | ||
color: #fff; | ||
padding: 8px; | ||
text-align: center; | ||
} | ||
|
||
td { | ||
padding: 20px; | ||
text-align: center; | ||
white-space: nowrap; | ||
overflow: hidden; | ||
text-overflow: ellipsis; | ||
border-bottom: 1px solid #D3D3D3; | ||
margin-bottom: 1px; | ||
} | ||
|
||
tbody tr:not(:first-child) { | ||
border: 1px solid black; | ||
} | ||
|
||
.short-column { | ||
width: 150px; | ||
} | ||
|
||
tfoot { | ||
text-align: center; | ||
font-style: italic; | ||
font-size: 12px; | ||
} | ||
|
||
#Chart { | ||
width: 800px; | ||
height: 400px; | ||
margin: 0 auto; | ||
} | ||
|
||
@font-face { | ||
font-family: Harmony; | ||
src: url("{{ custom_font }}"); | ||
} | ||
|
||
body { | ||
font-family: Harmony, sans-serif; | ||
font-size: 24px; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<table style="background-color: #FFFFFF"> | ||
<thead> | ||
<tr> | ||
<th class="short-column">日期</th> | ||
<th class="short-column">7881</th> | ||
<th class="short-column">万宝楼</th> | ||
<th class="short-column">DD373</th> | ||
<th class="short-column">5173</th> | ||
<th class="short-column">UU898</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{{ tablecontent }} | ||
<tr> | ||
<td colspan="6"> | ||
<div id="Chart"></div> | ||
</td> | ||
</tr> | ||
</tbody> | ||
<tfoot> | ||
<tr> | ||
<td colspan="6">© Inkar Suki · {{ app_name }} · {{ server }} · {{ app_time }}<br>{{ saohua }}</td> | ||
</tr> | ||
</tfoot> | ||
</table> | ||
|
||
<script src="https://cdn.jsdelivr.net/npm/echarts/dist/echarts.min.js"></script> | ||
<script> | ||
const chart = echarts.init(document.getElementById("Chart"), null, { devicePixelRatio: 2 }); | ||
|
||
const option = { | ||
animation: false, | ||
tooltip: { | ||
trigger: "axis" | ||
}, | ||
legend: { | ||
data: {{ platforms }} | ||
}, | ||
xAxis: { | ||
type: "category", | ||
boundaryGap: false, | ||
data: {{ dates }} | ||
}, | ||
yAxis: { | ||
type: "value", | ||
boundaryGap: [0, "100%"] | ||
}, | ||
series: [ | ||
{ | ||
name: "7881", | ||
type: "line", | ||
data: {{ _7881 }}, | ||
smooth: true, | ||
itemStyle: { | ||
color: "#42a5f5" | ||
}, | ||
areaStyle: { | ||
color: "rgba(66, 165, 245, 0.2)" | ||
} | ||
}, | ||
{ | ||
name: "万宝楼", | ||
type: "line", | ||
data: {{ wbl }}, | ||
smooth: true, | ||
itemStyle: { | ||
color: "#ff7043" | ||
}, | ||
areaStyle: { | ||
color: "rgba(255, 112, 67, 0.2)" | ||
} | ||
}, | ||
{ | ||
name: "DD373", | ||
type: "line", | ||
data: {{ dd373 }}, | ||
smooth: true, | ||
itemStyle: { | ||
color: "#30C701" | ||
}, | ||
areaStyle: { | ||
color: "rgba(48, 199, 1, 0.2)" | ||
} | ||
}, | ||
{ | ||
name: "5173", | ||
type: "line", | ||
data: {{ _5173 }}, | ||
smooth: true, | ||
itemStyle: { | ||
color: "#FF768B" | ||
}, | ||
areaStyle: { | ||
color: "rgba(255, 118, 139, 0.2)" | ||
} | ||
}, | ||
{ | ||
name: "UU898", | ||
type: "line", | ||
data: {{ uu898 }}, | ||
smooth: true, | ||
itemStyle: { | ||
color: "#5DA0ED" | ||
}, | ||
areaStyle: { | ||
color: "rgba(93, 160, 237, 0.2)" | ||
} | ||
} | ||
] | ||
}; | ||
|
||
chart.setOption(option); | ||
</script> | ||
</body> | ||
|
||
</html> |