Skip to content

Commit a1a6243

Browse files
xyqferDIYgod
authored andcommitted
feat: Add Sina rollnews (#2064)
1 parent b8a9c15 commit a1a6243

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

docs/traditional-media.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,8 @@ category 对应的关键词有
201201

202202
</Route>
203203

204+
<Route name="滚动新闻" author="xyqfer" example="/sina/rollnews" path="/sina/rollnews" />
205+
204206
## 人民日报
205207

206208
<Route name="观点" author="LogicJake" example="/people/opinion/223228" path="/people/opinion/:id" :paramsDesc="['板块id,可在 URL 中找到']"/>

lib/router.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,6 +1086,9 @@ router.get('/mpaypass/news', require('./routes/mpaypass/news'));
10861086
// 新浪科技探索
10871087
router.get('/sina/discovery/:type', require('./routes/sina/discovery'));
10881088

1089+
// 新浪科技滚动新闻
1090+
router.get('/sina/rollnews', require('./routes/sina/rollnews'));
1091+
10891092
// Animen
10901093
router.get('/animen/news/:type', require('./routes/animen/news'));
10911094

lib/routes/sina/rollnews.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const axios = require('../../utils/axios');
2+
const cheerio = require('cheerio');
3+
4+
module.exports = async (ctx) => {
5+
const response = await axios.get(`https://feed.mix.sina.com.cn/api/roll/get?pageid=372&lid=2431&k=&num=50&page=1&r=${Math.random()}&callback=&_=${new Date().getTime()}`);
6+
const list = response.data.result.data;
7+
8+
const out = await Promise.all(
9+
list.map(async (data) => {
10+
const title = data.title;
11+
const date = data.intime * 1000;
12+
const link = data.url;
13+
14+
const description = await ctx.cache.tryGet(
15+
`sina-rollnews: ${link}`,
16+
async () => {
17+
const response = await axios.get(link);
18+
const $ = cheerio.load(response.data);
19+
20+
return $('.article').html();
21+
},
22+
3 * 60 * 60
23+
);
24+
25+
const single = {
26+
title: title,
27+
link,
28+
description: description,
29+
pubDate: new Date(date).toUTCString(),
30+
};
31+
return Promise.resolve(single);
32+
})
33+
);
34+
35+
ctx.state.data = {
36+
title: '新浪科技滚动新闻',
37+
link: 'https://tech.sina.com.cn/roll/rollnews.shtml#pageid=372&lid=2431&k=&num=50&page=1',
38+
item: out,
39+
};
40+
};

0 commit comments

Comments
 (0)