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