feat(route): 东方网热点搜索 & 原创 (#8472)

This commit is contained in:
Ethan Shen
2021-11-27 08:49:51 +00:00
committed by GitHub
parent adf9fdff96
commit 3ff4950450
6 changed files with 132 additions and 1 deletions
+9 -1
View File
@@ -624,7 +624,15 @@ IT・科学 tech_science
### 上海新闻
<Route author="saury" example="/eastday/sh" path="/eastday/sh" />
<Route author="saury" example="/eastday/sh" path="/eastday/sh"/>
### 热点搜索
<Route author="nczitzk" example="/eastday/find" path="/eastday/find"/>
### 原创
<Route author="nczitzk" example="/eastday/portrait" path="/eastday/portrait"/>
## 読売新聞
+49
View File
@@ -0,0 +1,49 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const timezone = require('@/utils/timezone');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const rootUrl = 'https://apin.eastday.com';
const currentUrl = `${rootUrl}/api/news/Find`;
const response = await got({
method: 'post',
url: currentUrl,
json: {
currentPage: 1,
newsType: 1,
pageSize: 30,
query: '',
},
});
const list = response.data.newsList.list.map((item) => ({
link: item.url,
title: item.title,
pubDate: timezone(parseDate(item.time), +8),
}));
const items = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);
item.description = content('.detail').html();
return item;
})
)
);
ctx.state.data = {
title: '热点搜索 - 东方网',
link: 'https://news.eastday.com/china/index_K43594.html',
item: items,
};
};
+4
View File
@@ -0,0 +1,4 @@
module.exports = {
'/find': ['nczitzk'],
'/portrait': ['nczitzk'],
};
+47
View File
@@ -0,0 +1,47 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const timezone = require('@/utils/timezone');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const rootUrl = 'https://apin.eastday.com';
const currentUrl = `${rootUrl}/api/news/Portrait`;
const response = await got({
method: 'post',
url: currentUrl,
json: {
currentPage: 1,
pageSize: 30,
},
});
const list = response.data.list.map((item) => ({
link: item.url,
title: item.title,
pubDate: timezone(parseDate(item.time), +8),
}));
const items = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);
item.description = content('.detail').html();
return item;
})
)
);
ctx.state.data = {
title: '原创 - 东方网',
link: 'https://www.eastday.com/eastday/shouye/07index/yc/index.html',
item: items,
};
};
+19
View File
@@ -0,0 +1,19 @@
module.exports = {
'eastday.com': {
_name: '东方网',
www: [
{
title: '热点搜索',
docs: 'https://docs.rsshub.app/traditional-media.html#dong-fang-wang-re-dian-sou-suo',
source: '/',
target: '/eastday/find',
},
{
title: '原创',
docs: 'https://docs.rsshub.app/traditional-media.html#dong-fang-wang-yuan-chuang',
source: '/',
target: '/eastday/portrait',
},
],
},
};
+4
View File
@@ -0,0 +1,4 @@
module.exports = function (router) {
router.get('/find', require('./find'));
router.get('/portrait', require('./portrait'));
};