@@ -4,7 +4,7 @@ import type { RouterMiddleware } from '@oak/oak'
44
55class ServiceWeibo {
66 COOKIE =
7- 'SUB=_2AkMflEwGf8NxqwFRmvsXxG7ia4h2wwrEieKpyL3dJRM3HRl-yT9yqk4mtRB6NBRi6maz6YaTyfIClrCyCUrm0-7nB1R9 ; SUBP=0033WrSXqPxfM72-Ws9jqgMF55529P9D9WhR9EPgz3BDPWy-YHwFuiIb; MLOGIN=0; _T_WM=29824971760 ; XSRF-TOKEN=3e7411; WEIBOCN_FROM=1110006030; mweibo_short_token=0f127e0728; M_WEIBOCN_PARAMS=fid %3D106003type%253D25%2526t%253D3%2526disable_hot%253D1%2526filter_type%253Drealtimehot%26uicode%3D10000011'
7+ 'WEIBOCN_FROM=1110006030; SUB=_2AkMe1h3tf8NxqwFRmvsXxG7ia4h2wwrEieKoiuw2JRM3HRl-yT9kqnc9tRB6NVYzAmxCM1izZSWe9-xcPQmmL_NGEnIl ; SUBP=0033WrSXqPxfM72-Ws9jqgMF55529P9D9WhR9EPgz3BDPWy-YHwFuiIb; MLOGIN=0; _T_WM=38152265571 ; XSRF-TOKEN=86baeb; M_WEIBOCN_PARAMS=luicode%3D10000011%26lfid%3D102803%26launchid%3D10000360-page_H5%26fid %3D106003type%253D25%2526t%253D3%2526disable_hot%253D1%2526filter_type%253Drealtimehot%26uicode%3D10000011'
88
99 handle ( ) : RouterMiddleware < '/weibo' > {
1010 return async ( ctx ) => {
@@ -13,15 +13,15 @@ class ServiceWeibo {
1313 switch ( ctx . state . encoding ) {
1414 case 'text' :
1515 ctx . response . body = `微博实时热搜\n\n${ data
16- . map ( ( e , i ) => `${ i + 1 } . ${ e . title } ` )
16+ . map ( ( e , i ) => `${ i + 1 } . ${ e . title } ( ${ e . hot_value } ) ` )
1717 . slice ( 0 , 20 )
1818 . join ( '\n' ) } `
1919 break
2020
2121 case 'markdown' :
2222 ctx . response . body = `# 微博实时热搜\n\n${ data
2323 . slice ( 0 , 20 )
24- . map ( ( e , i ) => `${ i + 1 } . [${ e . title } ](${ e . link } )` )
24+ . map ( ( e , i ) => `${ i + 1 } . [${ e . title } ](${ e . link } ) ( ${ e . hot_value } ) ` )
2525 . join ( '\n' ) } `
2626 break
2727
@@ -36,6 +36,7 @@ class ServiceWeibo {
3636 async #fetch( ) {
3737 const api =
3838 'https://m.weibo.cn/api/container/getIndex?containerid=106003type%3D25%26t%3D3%26disable_hot%3D1%26filter_type%3Drealtimehot'
39+
3940 const { data = { } } = await (
4041 await fetch ( api , {
4142 headers : {
@@ -44,15 +45,19 @@ class ServiceWeibo {
4445 } ,
4546 } )
4647 ) . json ( )
47- return ( ( ( data ?. cards ?. [ 0 ] ?. card_group || [ ] ) as Item [ ] ) . filter ( ( e ) => ! e . pic . includes ( 'stick' ) ) || [ ] ) . map (
48- ( e ) => ( {
49- title : e . desc ,
50- hot_value : typeof e . desc_extr === 'number'
51- ? e . desc_extr
52- : parseInt ( String ( e . desc_extr ) . replace ( / \D / g, '' ) ) || 0 ,
53- link : `https://s.weibo.com/weibo?q=${ encodeURIComponent ( e . desc ) } ` ,
54- } ) ,
55- )
48+
49+ const list = ( data ?. cards ?. [ 0 ] ?. card_group || [ ] ) as Item [ ]
50+ const hot_value_regex = / (?< value > \d + ) / i
51+
52+ return list
53+ . filter ( ( e ) => / i m g _ s e a r c h _ \d + / . test ( e . pic ) ) // img_search_1 这样的才是热搜榜单,其他都是推广
54+ . map ( ( e ) => {
55+ return {
56+ title : e . desc ,
57+ hot_value : + ( hot_value_regex . exec ( String ( e . desc_extr || '' ) ) ?. groups ?. value || 0 ) ,
58+ link : `https://s.weibo.com/weibo?q=${ encodeURIComponent ( e . desc ) } ` ,
59+ }
60+ } )
5661 }
5762}
5863
0 commit comments