Skip to content
This repository was archived by the owner on Feb 20, 2026. It is now read-only.

Commit 267b211

Browse files
committed
chore: 更新额外脚本提供更多信息
1 parent a5d0cfe commit 267b211

File tree

1 file changed

+69
-2
lines changed
  • extra-scripts/travellings-cn-api

1 file changed

+69
-2
lines changed

extra-scripts/travellings-cn-api/main.py

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,31 @@
55

66
import requests
77

8+
RESET_COLOR = "\033[0m"
9+
10+
11+
def color_builder(percentage: float, type: str) -> str:
12+
"""根据百分比返回相应的颜色代码"""
13+
if percentage < 40:
14+
color_code = "\033[35m"
15+
elif percentage < 60:
16+
color_code = "\033[91m"
17+
elif percentage < 80:
18+
color_code = "\033[93m"
19+
else:
20+
color_code = "\033[92m"
21+
22+
if type == "origin":
23+
color_code += f"{percentage}"
24+
elif type == ".2f":
25+
color_code += f"{percentage:.2f}"
26+
elif type == "<5":
27+
color_code += f"{percentage:<5}"
28+
elif type == ">5":
29+
color_code += f"{percentage:<5}"
30+
31+
return color_code + RESET_COLOR
32+
833

934
def main() -> None:
1035
# 创建 temp 目录(如果不存在)
@@ -26,12 +51,54 @@ def main() -> None:
2651

2752
# 读取 all.json,将 status 不为 RUN 的 url 写入 input.txt
2853

54+
run_counters = {}
55+
all_counters = {}
56+
wait_counters = {}
57+
58+
counter_increment = lambda d, k: d.update({k: d.get(k, 0) + 1})
59+
2960
with open("./temp/all.json", "r", encoding="utf-8") as f:
3061
data = json.load(f)
3162
with open("input.txt", "w", encoding="utf-8") as f:
3263
for item in data["data"]:
33-
if item["status"] != "RUN":
34-
f.write(item["url"].strip() + "\n")
64+
index = (item["id"] - 1) // 100 + 1 # index = 1 : 1-100
65+
66+
counter_increment(all_counters, index)
67+
68+
if item["status"] == "RUN":
69+
counter_increment(run_counters, index)
70+
continue
71+
72+
f.write(item["url"].strip() + "\n")
73+
74+
if item["status"] == "WAIT":
75+
counter_increment(wait_counters, index)
76+
continue
77+
78+
print(" Range RUN/TOTAL RUN/(TOTAL-WAIT)")
79+
80+
for key in sorted(run_counters.keys()):
81+
print(
82+
f"{(key-1)*100+1:>4}-{key*100:<4}:"
83+
f"{run_counters.get(key,0):>5}/{all_counters.get(key,0):<5}({color_builder((run_counters.get(key,0) / all_counters.get(key,0)) * 100,".2f")}%)",
84+
end="",
85+
)
86+
print(
87+
f"{run_counters.get(key,0):>5}/{all_counters.get(key,0)-wait_counters.get(key,0):<5}({color_builder((run_counters.get(key,0) / (all_counters.get(key,0)-wait_counters.get(key,0))) * 100,".2f")}%)"
88+
)
89+
total_run = sum(run_counters.values())
90+
total_all = sum(all_counters.values())
91+
total_wait = sum(wait_counters.values())
92+
print(
93+
f"Total: {total_run:>5}/{total_all:<5}({color_builder((total_run / total_all) * 100, ".2f")}%)",
94+
end="",
95+
)
96+
print(
97+
f"{total_run:>5}/{total_all-total_wait:<5}({color_builder((total_run / (total_all-total_wait)) * 100, ".2f")}%)"
98+
)
99+
print(
100+
"解释: RUN/TOTAL 是不可控的,除非全部站长都能正常维持站点。此外开往维护组应尽可能提高 RUN/(TOTAL-WAIT) 的比值。"
101+
)
35102

36103

37104
if __name__ == "__main__":

0 commit comments

Comments
 (0)