1+ from widget import Widget , family , SMALL , MEDIUM , LARGE
2+ import requests
3+
4+ def safe_text (val , default = "" ):
5+ return val if val and val .strip () else default
6+
7+ try :
8+ headers = {"Content-Type" : "application/x-www-form-urlencoded;charset:utf-8" }
9+ resp = requests .post (
10+ "https://api.taolale.com/api/hot_rankings/get" ,
11+ data = {"key" : "DoG1KYTwfGhcTACTpgAk4eFiDf" },
12+ headers = headers ,
13+ timeout = 10
14+ )
15+ data = resp .json ()
16+ movies = data .get ("data" , [])[:5 ] if data .get ("code" ) == 200 else []
17+ except :
18+ movies = []
19+
20+ bg = ("#F8FAFC" , "#0F172A" )
21+ title_color = ("#0F172A" , "#F8FAFC" )
22+ subtitle_color = ("#647B94" , "#94A3B8" )
23+ accent = "#EF4444"
24+
25+ w = Widget (background = bg , padding = 14 )
26+
27+ if family == SMALL :
28+ top = movies [0 ] if movies else None
29+ with w .vstack (spacing = 0 , align = "leading" ):
30+ w .spacer (24 )
31+ if top :
32+ w .icon ("film.fill" , size = 18 , color = accent )
33+ w .spacer (8 )
34+ w .text (top ["title" ], size = 17 , weight = "bold" , color = title_color , max_lines = 1 )
35+ w .spacer (6 )
36+ w .text (top ["sumBoxDesc" ], size = 24 , weight = "bold" , design = "rounded" , color = title_color )
37+ release_info = safe_text (top .get ("releaseInfo" ))
38+ if release_info :
39+ w .spacer (6 )
40+ w .text (release_info , size = 12 , color = subtitle_color )
41+ else :
42+ w .text ("暂无数据" , size = 16 , color = subtitle_color )
43+ w .spacer ()
44+
45+ elif family == MEDIUM :
46+ with w .hstack (spacing = 0 ):
47+ w .icon ("film.fill" , size = 15 , color = accent )
48+ w .spacer (6 )
49+ w .text ("实时票房前三" , size = 14 , weight = "semibold" , color = title_color )
50+ w .spacer ()
51+ #w.text(f"共{len(movies)}部", size=12, color=subtitle_color)
52+ w .spacer ()
53+ for movie in movies [:3 ]:
54+ rank = movie ["index" ]
55+ rc = "#F59E0B" if rank == 1 else "#94A3B8" if rank == 2 else "#CD7F32"
56+ with w .hstack (spacing = 0 , align = "center" ):
57+ w .text (f"#{ rank } " , size = 13 , weight = "bold" , color = rc )
58+ w .spacer (6 )
59+ w .text (movie ["title" ], size = 13 , weight = "medium" , color = title_color )
60+ w .spacer ()
61+ w .text (movie ["sumBoxDesc" ], size = 13 , weight = "bold" , design = "rounded" , color = title_color )
62+ w .spacer (4 )
63+ w .spacer ()
64+
65+ else :
66+ with w .hstack (spacing = 0 ):
67+ w .icon ("film.fill" , size = 17 , color = accent )
68+ w .spacer (8 )
69+ w .text ("实时票房榜" , size = 17 , weight = "bold" , color = title_color )
70+ w .spacer ()
71+ w .text (f"共{ len (movies )} 部" , size = 13 , color = subtitle_color )
72+ w .spacer (12 )
73+ for movie in movies :
74+ rank = movie ["index" ]
75+ rc = "#F59E0B" if rank == 1 else "#94A3B8" if rank == 2 else "#CD7F32"
76+ release_info = safe_text (movie .get ("releaseInfo" ))
77+ with w .hstack (spacing = 0 , align = "center" ):
78+ w .text (f"#{ rank } " , size = 15 , weight = "bold" , color = rc )
79+ w .spacer (8 )
80+ w .text (movie ["title" ], size = 15 , weight = "semibold" , color = title_color )
81+ if release_info :
82+ w .text (f" · { release_info } " , size = 12 , color = subtitle_color )
83+ w .spacer ()
84+ w .text (movie ["sumBoxDesc" ], size = 16 , weight = "bold" , design = "rounded" , color = title_color )
85+ w .spacer (6 )
86+
87+ w .render ()
0 commit comments