-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathscript_mnj1lj72.py
More file actions
93 lines (78 loc) · 3.16 KB
/
Copy pathscript_mnj1lj72.py
File metadata and controls
93 lines (78 loc) · 3.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# 2026-4-3 Silence
import requests
from widget import Widget, family, MEDIUM
BLACKLIST = ["死", "杀", "恨", "怨", "哭", "泪", "痛", "苦", "穷",
"失败", "绝望", "黑暗", "孤独", "放弃", "离开", "背叛",
"悲伤", "痛苦", "哭泣", "受伤", "残忍", "抑郁", "焦虑", "堕落"]
def is_good(text):
for w in BLACKLIST:
if w in text:
return False
return True
def get_motto():
categories = ['d', 'i', 'k']
for _ in range(8):
try:
import random
cat = random.choice(categories)
url = f"https://v1.hitokoto.cn/?c={cat}"
resp = requests.get(url, timeout=5)
if resp.status_code == 200:
data = resp.json()
text = data.get('hitokoto', '')
if not text or len(text) < 8 or len(text) > 24:
continue
if not is_good(text):
continue
from_who = data.get('from_who', '')
from_where = data.get('from', '')
if from_who and from_where:
if from_who in from_where or from_where in from_who:
author = from_who if from_who else from_where
else:
author = f"{from_who} · {from_where}"
elif from_who:
author = from_who
elif from_where:
author = from_where
else:
author = ""
return text, author
except:
pass
return "每天进步一点点,坚持带来大改变。", "佚名"
def render_widget():
quote, author = get_motto()
if len(quote) > 22:
quote = quote[:20] + "…"
bg_color = ("#FEFCE8", "#1E1A2F")
w = Widget(background=bg_color, padding=16)
with w.vstack(spacing=10):
with w.hstack():
w.icon("heart.text.square.fill", size=18, color="#E63946")
w.text("每日名言", size=14, weight="semibold", color=("#1E293B", "#E2E8F0"))
w.spacer()
w.icon("leaf.fill", size=12, color="#A3E635")
w.divider(color=("#E2E8F0", "#334155"))
with w.hstack():
w.icon("quote.opening", size=14, color=("#94A3B8", "#64748B"))
w.spacer(4)
w.spacer(4)
w.text(f"「{quote}」", size=15, weight="medium",
color=("#0F172A", "#F1F5F9"), align="left", max_lines=3)
w.spacer(4)
if author:
w.text(f"—— {author}", size=11, color=("#64748B", "#94A3B8"),
align="right", max_lines=1)
else:
w.text(" 给今天一点力量 ", size=10, color=("#94A3B8", "#6B7280"), align="center")
w.render()
if family == MEDIUM:
render_widget()
else:
w = Widget(background=("#FFFFFF", "#0B0F1A"), padding=16)
with w.vstack(align="center", spacing=8):
w.icon("heart.text.square", size=30, color="#E63946")
w.text("请使用中尺寸小组件", size=14, weight="semibold",
color=("#111", "#EEE"), align="center")
w.render()