fix(route): yomiuri news list structure changed (#9764)

This commit is contained in:
Arracc
2022-05-17 01:13:55 +08:00
committed by GitHub
parent 768a51f266
commit f7c02471d0
7 changed files with 46 additions and 28 deletions
+14
View File
@@ -502,6 +502,20 @@ Provides all of the articles by the specified Yahoo! author.
</RouteEn>
## Yomiuri Shimbun 読売新聞
### News
<RouteEn author="Arracc" example="/yomiuri/news" path="/yomiuri/:category" :paramsDesc="['category']">
Free articles only.
| 新着・速報 |   社会 | 政治 | 経済 | スポーツ | 国際 | 科学・IT | 選挙・世論調査 | エンタメ・文化 | 囲碁・将棋 | ライフ | 地域 | 社説 | 皇室 |
| ------- | -------- | -------- | ------- | ------ | ----- | ------- | -------- | ------- | --------- | ---- | ----- | --------- | --------- |
|  news   | national | politics | economy | sports | world | science | election | culture | igoshougi | life | local | editorial | koushitsu |
</RouteEn>
## 公視新聞網
### Daily News
+3 -3
View File
@@ -722,9 +722,9 @@ IT・科学 tech_science
无料全文,综合页 (新着・速報) 文章标题补充板块标签。
| 新着・速報 |   社会 | 政治 | 経済 | スポーツ | 国際 | 科学・IT | 選挙・世論調査 | エンタメ・文化 | 囲碁・将棋 | ライフ | 地域 | 社説 |
| ------- | -------- | -------- | ------- | ------ | ----- | ------- | -------- | ------- | --------- | ---- | ----- | --------- |
|  news   | national | politics | economy | sports | world | science | election | culture | igoshougi | life | local | editorial |
| 新着・速報 |   社会 | 政治 | 経済 | スポーツ | 国際 | 科学・IT | 選挙・世論調査 | エンタメ・文化 | 囲碁・将棋 | ライフ | 地域 | 社説 | 皇室 |
| ------- | -------- | -------- | ------- | ------ | ----- | ------- | -------- | ------- | --------- | ---- | ----- | --------- | --------- |
|  news   | national | politics | economy | sports | world | science | election | culture | igoshougi | life | local | editorial | koushitsu |
</Route>
+2 -2
View File
@@ -3280,8 +3280,8 @@ router.get('/nobelprize/:caty?', lazyloadRouteHandler('./routes/nobelprize/index
// 中華民國國防部
router.get('/gov/taiwan/mnd', lazyloadRouteHandler('./routes/gov/taiwan/mnd'));
// 読売新聞
router.get('/yomiuri/:category', lazyloadRouteHandler('./routes/yomiuri/news'));
// 読売新聞 to v2
// router.get('/yomiuri/:category', lazyloadRouteHandler('./routes/yomiuri/news'));
// 巴哈姆特
// GNN新闻 migrated to v2
+3
View File
@@ -0,0 +1,3 @@
module.exports = {
'/yomiuri/:category?': ['Arracc'],
};
@@ -1,6 +1,7 @@
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 category = ctx.params.category;
@@ -17,26 +18,8 @@ module.exports = async (ctx) => {
let list = null;
if (category === 'news') {
categoryName = '新着・速報';
const urlPrefix = 'https://www.yomiuri.co.jp/y_ajax/';
// get list1
const param1 = $('input#latest_list_news_other_params').val();
const response1 = await got({
method: 'get',
url: urlPrefix + 'latest_list_news/' + param1 + '/?action=latest_list_news&others=' + param1,
});
const data1 = response1.data;
const firstArticleList = cheerio.load(data1);
// get list2
const param2 = $('input#latest_list_news_other_params2').val();
const response2 = await got({
method: 'get',
url: urlPrefix + 'latest_list_news2/' + param2 + '/?action=latest_list_news2&others=' + param2,
});
const data2 = response2.data;
const secondArticleList = cheerio.load(data2);
list = secondArticleList('article').add(firstArticleList('article'));
list = $('div#latest_list_news').find('article').append($('div#latest_list_news_more').find('article'));
list = list.map((index, item) => {
item = $(item);
@@ -74,8 +57,9 @@ module.exports = async (ctx) => {
}
// format category name
let formattedCategoryName = categoryName;
if (categoryName !== '') {
categoryName = ' - ' + categoryName.trim();
formattedCategoryName = ' - ' + categoryName.trim();
}
const items = await Promise.all(
@@ -91,7 +75,7 @@ module.exports = async (ctx) => {
}
const description = await ctx.cache.tryGet(link, async () => {
const response = await got.get(link);
const response = await got(link);
const $ = cheerio.load(response.data);
const mainContent = $('div.p-main-contents');
// remove articles recomended
@@ -120,6 +104,7 @@ module.exports = async (ctx) => {
editorial: '社説',
medical: '医療・健康',
olympic: 'オリンピック',
koushitsu: '皇室',
};
const tag_value = tag_table[link.split('/')[3]];
tag = tag_value ? tag_value : 'その他';
@@ -129,7 +114,7 @@ module.exports = async (ctx) => {
return {
title: tag + item.find('a').text(),
description,
pubDate: timezone(new Date(item.find('time').prop('datetime')), +9),
pubDate: timezone(parseDate(item.find('time').prop('datetime')), +9),
link,
};
})
@@ -137,7 +122,7 @@ module.exports = async (ctx) => {
);
ctx.state.data = {
title: '読売新聞' + categoryName,
title: '読売新聞' + formattedCategoryName,
link: url,
item: items,
};
+13
View File
@@ -0,0 +1,13 @@
module.exports = {
'yomiuri.co.jp': {
_name: '読売新聞',
www: [
{
title: '読売新聞',
docs: 'https://docs.rsshub.app/traditional-media.html#du-mai-xin-wen',
source: ['/:category'],
target: '/yomiuri/:category',
},
],
},
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/:category?', require('./news'));
};