Skip to content

Commit c8002a5

Browse files
[投稿] 添加脚本: 流量小组件 — by Silence
1 parent f017825 commit c8002a5

1 file changed

Lines changed: 85 additions & 0 deletions

File tree

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# 欢迎使用 PythonIDE!如果觉得好用,请给个好评哦~
2+
import requests
3+
from widget import Widget, family
4+
from widget import SMALL, MEDIUM, LARGE, CIRCULAR, RECTANGULAR
5+
6+
7+
def get_unicom_data():
8+
9+
url = ''
10+
headers = {
11+
'Host': '',
12+
'User-Agent': '',
13+
'Cookie':
14+
#这里把你抓到的cookie放里面即可.
15+
'这里....'
16+
}
17+
try:
18+
res = requests.get(url, headers=headers, timeout=5)
19+
if res.status_code == 200:
20+
data = res.json()
21+
flow = data.get('flowResource', {}).get('flowPersent', '0')
22+
fee = data.get('feeResource', {}).get('feePersent', '0')
23+
voice = data.get('voiceResource', {}).get('voicePersent', '0')
24+
t = data.get("flush_date_time", "").split(" ")[-1] if " " in data.get("flush_date_time", "") else "刚刚"
25+
return True, flow, fee, voice, t
26+
except:
27+
pass
28+
return False, "0", "0", "0", "--"
29+
30+
31+
success, flow, fee, voice, update_time = get_unicom_data()
32+
33+
34+
w = Widget(
35+
background=("#FFFFFF", "#0B0F1A"), #
36+
padding=16
37+
)
38+
39+
if family == MEDIUM:
40+
41+
with w.hstack(spacing=0):
42+
43+
44+
with w.vstack(align="leading", spacing=0):
45+
46+
with w.hstack(spacing=6):
47+
w.icon("antenna.radiowaves.left.and.right", size=16, color="#E63946")
48+
w.text("中国联通", size=14, weight="bold", color=("#111", "#EEE"))
49+
50+
w.spacer(14)
51+
w.text("剩余通用流量", size=12, color=("#64748B", "#94A3B8"))
52+
w.spacer(4)
53+
54+
55+
with w.hstack(spacing=4, align="bottom"):
56+
57+
w.text(flow, size=36, weight="bold", design="rounded", color=("#000", "#FFF"))
58+
59+
w.text("GB", size=14, weight="bold", color="#E63946")
60+
61+
62+
w.spacer()
63+
64+
65+
with w.vstack(align="leading", spacing=10):
66+
w.spacer(6)
67+
68+
69+
with w.hstack(spacing=8):
70+
w.icon("yensign.circle.fill", size=14, color="#F59E0B")
71+
w.text(f"{fee} 元", size=11, weight="semibold", color="#F59E0B")
72+
73+
74+
with w.hstack(spacing=8):
75+
w.icon("phone.fill", size=14, color="#10B981")
76+
w.text(f"{voice} 分钟", size=11, weight="semibold", color="#10B981")
77+
78+
79+
with w.hstack(spacing=8):
80+
w.icon("clock", size=14, color=("#94A3B8", "#64748B"))
81+
w.text(update_time, size=11, color=("#94A3B8", "#64748B"))
82+
83+
84+
w.render()
85+
#2026-3-19

0 commit comments

Comments
 (0)