feat: add futunn lighlights (#4945)

This commit is contained in:
Zhengyuan Wei
2020-06-09 11:23:13 +08:00
committed by GitHub
parent efe68f366f
commit 70dcecc69f
3 changed files with 64 additions and 0 deletions
+6
View File
@@ -36,6 +36,12 @@ pageClass: routes
<Route author="nczitzk" example="/cls/depth" path="/cls/depth"/>
## 富途牛牛
### 要闻
<Route author="Wsine" example="/futunn/highlights" path="/futunn/highlights" />
## 淘股吧股票论坛
### 论坛总版
+3
View File
@@ -2838,4 +2838,7 @@ router.get('/gov/chinatax/latest', require('./routes/gov/chinatax/latest'));
// 荔枝FM
router.get('/lizhi/user/:id', require('./routes/lizhi/user'));
// 富途牛牛
router.get('/futunn/highlights', require('./routes/futunn/highlights'));
module.exports = router;
+55
View File
@@ -0,0 +1,55 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const date_util = require('@/utils/date');
module.exports = async (ctx) => {
const link = `https://news.futunn.com/main`;
const response = await got.get(link);
const $ = cheerio.load(response.data);
// extract json from 'window._params = {...};'
const params = $('script:not([src])').html().trim().slice(17, -1);
const newslist = JSON.parse(params).preList;
const out = await Promise.all(
newslist.map(async (info) => {
const title = info.title;
const itemUrl = info.url;
const cache = await ctx.cache.get(itemUrl);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
const response = await got({
url: itemUrl,
method: 'get',
headers: {
Referer: link,
},
});
const $ = cheerio.load(response.data);
const description = $('div.newsDetailBox div.main div.inner').html() || '原文已被删除';
const date = $('div.timeBar').text();
const single = {
title: title,
link: itemUrl,
description: description,
pubDate: date_util(date, 8),
};
ctx.cache.set(itemUrl, JSON.stringify(single));
return Promise.resolve(single);
})
);
ctx.state.data = {
title: `富途牛牛要闻`,
link: link,
item: out,
};
};