在准备环境前提交次全部更改。
This commit is contained in:
55
scripts/ops/fix_date_dividers.py
Normal file
55
scripts/ops/fix_date_dividers.py
Normal file
@@ -0,0 +1,55 @@
|
||||
"""批量替换 performance.html 中的日期分割线,加上时长和收入信息"""
|
||||
import re, random
|
||||
|
||||
filepath = "docs/h5_ui/pages/performance.html"
|
||||
|
||||
with open(filepath, "r", encoding="utf-8") as f:
|
||||
content = f.read()
|
||||
|
||||
# 2月日期 → 当月,显示"预估收入"
|
||||
# 1月日期 → 上月,显示"收入"
|
||||
feb_stats = {
|
||||
"2月7日": "时长 4.0h · 预估收入 ¥350",
|
||||
"2月6日": "时长 3.5h · 预估收入 ¥280",
|
||||
"2月5日": "时长 4.0h · 预估收入 ¥320",
|
||||
"2月4日": "时长 4.0h · 预估收入 ¥350",
|
||||
"2月3日": "时长 3.5h · 预估收入 ¥280",
|
||||
"2月2日": "时长 4.0h · 预估收入 ¥350",
|
||||
"2月1日": "时长 6.0h · 预估收入 ¥510",
|
||||
}
|
||||
jan_stats = {
|
||||
"1月31日": "时长 5.5h · 收入 ¥470",
|
||||
"1月30日": "时长 3.5h · 收入 ¥280",
|
||||
"1月29日": "时长 4.0h · 收入 ¥320",
|
||||
"1月28日": "时长 4.0h · 收入 ¥350",
|
||||
"1月27日": "时长 4.0h · 收入 ¥350",
|
||||
"1月26日": "时长 2.0h · 收入 ¥160",
|
||||
"1月25日": "时长 2.0h · 收入 ¥160",
|
||||
"1月24日": "时长 1.5h · 收入 ¥120",
|
||||
"1月23日": "时长 2.0h · 收入 ¥160",
|
||||
"1月22日": "时长 2.0h · 收入 ¥190",
|
||||
"1月21日": "时长 2.0h · 收入 ¥160",
|
||||
"1月20日": "时长 3.5h · 收入 ¥280",
|
||||
"1月19日": "时长 4.0h · 收入 ¥350",
|
||||
"1月18日": "时长 2.0h · 收入 ¥160",
|
||||
"1月17日": "时长 3.5h · 收入 ¥280",
|
||||
"1月16日": "时长 4.0h · 收入 ¥350",
|
||||
"1月15日": "时长 2.0h · 收入 ¥190",
|
||||
}
|
||||
all_stats = {**feb_stats, **jan_stats}
|
||||
|
||||
# 匹配 <div class="date-divider" ...><span>日期</span></div>
|
||||
pattern = r'<div class="date-divider"([^>]*)><span>([^<]+)</span></div>'
|
||||
|
||||
def replacer(m):
|
||||
attrs = m.group(1)
|
||||
date_text = m.group(2)
|
||||
stats = all_stats.get(date_text, f"时长 2.0h · 收入 ¥160")
|
||||
return f'<div class="date-divider"{attrs}><span class="dd-date">{date_text}</span><div class="dd-line"></div><span class="dd-stats">{stats}</span></div>'
|
||||
|
||||
new_content = re.sub(pattern, replacer, content)
|
||||
|
||||
with open(filepath, "w", encoding="utf-8") as f:
|
||||
f.write(new_content)
|
||||
|
||||
print(f"Done. Replaced date dividers in {filepath}")
|
||||
Reference in New Issue
Block a user