Skip to content

Commit 439d104

Browse files
Merge pull request #89 from jinwandalaohu66/submission/script_mnj1lj72
2 parents 96382fd + 6d077b8 commit 439d104

2 files changed

Lines changed: 118 additions & 2 deletions

File tree

script_library/index.json

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"format_version": 1,
3-
"data_version": 65,
4-
"updated": "2026-04-03T10:40:27.436Z",
3+
"data_version": 66,
4+
"updated": "2026-04-03T15:12:30.481Z",
55
"announcement": null,
66
"categories": [
77
{
@@ -1282,6 +1282,29 @@
12821282
"updated": null,
12831283
"status": "active",
12841284
"lines": 93
1285+
},
1286+
{
1287+
"id": "script_mnj1lj72",
1288+
"name": "每日名言",
1289+
"name_en": "每日名言",
1290+
"desc": "每日名言,仅仅支持中组件",
1291+
"desc_en": "每日名言,仅仅支持中组件",
1292+
"category": "widgets",
1293+
"file": "scripts/widgets/script_mnj1lj72.py",
1294+
"thumbnail": null,
1295+
"version": 1,
1296+
"file_type": "py",
1297+
"author": "Silence",
1298+
"author_en": "Silence",
1299+
"tags": [
1300+
"community"
1301+
],
1302+
"requires": [],
1303+
"min_app_version": "1.5.0",
1304+
"added": "2026-04-03",
1305+
"updated": null,
1306+
"status": "active",
1307+
"lines": 93
12851308
}
12861309
]
12871310
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
2+
# 2026-4-3 Silence
3+
4+
import requests
5+
from widget import Widget, family, MEDIUM
6+
7+
BLACKLIST = ["死", "杀", "恨", "怨", "哭", "泪", "痛", "苦", "穷",
8+
"失败", "绝望", "黑暗", "孤独", "放弃", "离开", "背叛",
9+
"悲伤", "痛苦", "哭泣", "受伤", "残忍", "抑郁", "焦虑", "堕落"]
10+
11+
def is_good(text):
12+
for w in BLACKLIST:
13+
if w in text:
14+
return False
15+
return True
16+
17+
def get_motto():
18+
categories = ['d', 'i', 'k']
19+
for _ in range(8):
20+
try:
21+
import random
22+
cat = random.choice(categories)
23+
url = f"https://v1.hitokoto.cn/?c={cat}"
24+
resp = requests.get(url, timeout=5)
25+
if resp.status_code == 200:
26+
data = resp.json()
27+
text = data.get('hitokoto', '')
28+
if not text or len(text) < 8 or len(text) > 24:
29+
continue
30+
if not is_good(text):
31+
continue
32+
from_who = data.get('from_who', '')
33+
from_where = data.get('from', '')
34+
if from_who and from_where:
35+
if from_who in from_where or from_where in from_who:
36+
author = from_who if from_who else from_where
37+
else:
38+
author = f"{from_who} · {from_where}"
39+
elif from_who:
40+
author = from_who
41+
elif from_where:
42+
author = from_where
43+
else:
44+
author = ""
45+
return text, author
46+
except:
47+
pass
48+
return "每天进步一点点,坚持带来大改变。", "佚名"
49+
50+
def render_widget():
51+
quote, author = get_motto()
52+
if len(quote) > 22:
53+
quote = quote[:20] + "…"
54+
55+
bg_color = ("#FEFCE8", "#1E1A2F")
56+
w = Widget(background=bg_color, padding=16)
57+
58+
with w.vstack(spacing=10):
59+
with w.hstack():
60+
w.icon("heart.text.square.fill", size=18, color="#E63946")
61+
w.text("每日名言", size=14, weight="semibold", color=("#1E293B", "#E2E8F0"))
62+
w.spacer()
63+
w.icon("leaf.fill", size=12, color="#A3E635")
64+
65+
w.divider(color=("#E2E8F0", "#334155"))
66+
67+
with w.hstack():
68+
w.icon("quote.opening", size=14, color=("#94A3B8", "#64748B"))
69+
w.spacer(4)
70+
w.spacer(4)
71+
72+
w.text(f"「{quote}」", size=15, weight="medium",
73+
color=("#0F172A", "#F1F5F9"), align="left", max_lines=3)
74+
75+
w.spacer(4)
76+
77+
if author:
78+
w.text(f"—— {author}", size=11, color=("#64748B", "#94A3B8"),
79+
align="right", max_lines=1)
80+
else:
81+
w.text(" 给今天一点力量 ", size=10, color=("#94A3B8", "#6B7280"), align="center")
82+
83+
w.render()
84+
85+
if family == MEDIUM:
86+
render_widget()
87+
else:
88+
w = Widget(background=("#FFFFFF", "#0B0F1A"), padding=16)
89+
with w.vstack(align="center", spacing=8):
90+
w.icon("heart.text.square", size=30, color="#E63946")
91+
w.text("请使用中尺寸小组件", size=14, weight="semibold",
92+
color=("#111", "#EEE"), align="center")
93+
w.render()

0 commit comments

Comments
 (0)