1+ # 2026-3-23 by.Silence 测试设备16.2 14pm
2+ import requests
3+ from widget import Widget , family
4+ from widget import SMALL , MEDIUM , LARGE , CIRCULAR , RECTANGULAR
5+ from datetime import datetime
6+
7+
8+ def get_unicom_data ():
9+ url = '自行填写'
10+ headers = {
11+ 'Host' : 'm.client.10010.com' ,
12+ 'User-Agent' : '自行填写' ,
13+ 'Cookie' : '自行填写'
14+ }
15+ try :
16+ res = requests .get (url , headers = headers , timeout = 5 )
17+ if res .status_code == 200 :
18+ data = res .json ()
19+ flow = data .get ('flowResource' , {}).get ('flowPersent' , '0' )
20+ fee = data .get ('feeResource' , {}).get ('feePersent' , '0' )
21+ voice = data .get ('voiceResource' , {}).get ('voicePersent' , '0' )
22+ t = data .get ("flush_date_time" , "" ).split (" " )[- 1 ] if " " in data .get ("flush_date_time" , "" ) else "刚刚"
23+ return True , flow , fee , voice , t
24+ except :
25+ pass
26+ return False , "0" , "0" , "0" , "--"
27+
28+
29+ def get_date_tip ():
30+ now = datetime .now ()
31+ week_list = ["周一" , "周二" , "周三" , "周四" , "周五" , "周六" , "周日" ]
32+ week_day = week_list [now .weekday ()]
33+ month_day = now .strftime ("%m月%d日" )
34+
35+ year_start = datetime (now .year , 1 , 1 )
36+ year_end = datetime (now .year + 1 , 1 , 1 )
37+ year_pass = (now - year_start ).total_seconds ()
38+ year_total = (year_end - year_start ).total_seconds ()
39+ year_percent = int ((year_pass / year_total ) * 100 )
40+ return f"{ week_day } { month_day } · 今年已过{ year_percent } %"
41+
42+
43+ success , flow , fee , voice , update_time = get_unicom_data ()
44+ date_tip = get_date_tip ()
45+
46+ w = Widget (
47+ background = ("#FFFFFF" , "#0B0F1A" ),
48+ padding = 16
49+ )
50+
51+ if family == MEDIUM :
52+ with w .hstack (spacing = 0 ):
53+
54+
55+ with w .vstack (align = "leading" , spacing = 0 ):
56+ with w .hstack (spacing = 6 , align = "center" ):
57+ w .icon ("antenna.radiowaves.left.and.right" , size = 16 , color = "#E63946" )
58+ w .text ("中国联通" , size = 14 , weight = "bold" , color = ("#111" , "#EEE" ), max_lines = 1 )
59+
60+ w .spacer (14 )
61+ w .text ("剩余通用流量" , size = 12 , color = ("#64748B" , "#94A3B8" ), max_lines = 1 )
62+ w .spacer (4 )
63+
64+ with w .hstack (spacing = 4 , align = "bottom" ):
65+ w .text (flow , size = 36 , weight = "bold" , design = "rounded" , color = ("#000" , "#FFF" ), max_lines = 1 )
66+ w .text ("GB" , size = 14 , weight = "bold" , color = "#E63946" , max_lines = 1 )
67+
68+
69+ w .spacer (8 )
70+ w .text (date_tip , size = 11 , color = ("#94A3B8" , "#64748B" ), max_lines = 1 )
71+
72+ w .spacer ()
73+
74+
75+ with w .vstack (align = "leading" , spacing = 10 ):
76+ w .spacer (6 )
77+
78+ with w .hstack (spacing = 8 , align = "center" ):
79+ w .icon ("yensign.circle.fill" , size = 14 , color = "#F59E0B" )
80+ w .text (f"{ fee } 元" , size = 11 , weight = "semibold" , color = "#F59E0B" , max_lines = 1 )
81+
82+ with w .hstack (spacing = 8 , align = "center" ):
83+ w .icon ("phone.fill" , size = 14 , color = "#10B981" )
84+ w .text (f"{ voice } 分钟" , size = 11 , weight = "semibold" , color = "#10B981" , max_lines = 1 )
85+
86+ with w .hstack (spacing = 8 , align = "center" ):
87+ w .icon ("clock" , size = 14 , color = ("#94A3B8" , "#64748B" ))
88+ w .text (update_time , size = 11 , color = ("#94A3B8" , "#64748B" ), max_lines = 1 )
89+
90+
91+ if not success :
92+ w = Widget (background = ("#FFFFFF" , "#0B0F1A" ), padding = 16 )
93+ with w .vstack (align = "center" , spacing = 8 ):
94+ w .spacer ()
95+ w .icon ("wifi.exclamationmark" , size = 30 , color = ("#64748B" , "#94A3B8" ))
96+ w .text ("数据获取失败" , size = 14 , weight = "semibold" , color = ("#111" , "#EEE" ), max_lines = 1 )
97+ w .text ("请更新Cookie" , size = 12 , color = ("#64748B" , "#94A3B8" ), max_lines = 1 )
98+ w .spacer ()
99+
100+ w .render (url = "pythonide://" )
0 commit comments