feat(route): add 華視新聞網 (#10658)

* feat(route): add 華視新聞網

* fix(route): rate limit

* feat(route): description uses HTML instead of raw text
This commit is contained in:
miles 2022-08-30 20:53:52 +08:00 committed by GitHub
parent 3a65aec136
commit 3c7cd655e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 71 additions and 0 deletions

View File

@ -1152,6 +1152,18 @@ Type 栏目:
</Route>
## 華視
### 新聞
<Route author="miles170" example="/cts/real" path="/cts/:category" :paramsDesc="['类别']" radar="1">
| 即時 | 氣象 | 政治 | 國際 | 社會 | 運動 | 生活 | 財經 | 台語 | 地方 | 產業 | 綜合 | 藝文 | 娛樂 |
| ---- | ------- | -------- | ------------- | ------- | ------ | ---- | ----- | --------- | ----- | -- | ------- | ---- | --------- |
| real | weather | politics | international | society | sports | life | money | taiwanese | local | pr | general | arts | entertain |
</Route>
## 环球网
### 分类

3
lib/v2/cts/maintainer.js Normal file
View File

@ -0,0 +1,3 @@
module.exports = {
'/:category': ['miles170'],
};

40
lib/v2/cts/news.js Normal file
View File

@ -0,0 +1,40 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const asyncPool = require('tiny-async-pool');
module.exports = async (ctx) => {
const category = ctx.params.category;
const currentUrl = `https://news.cts.com.tw/${category}/index.html`;
const response = await got(currentUrl);
const $ = cheerio.load(response.data);
const items = [];
for await (const data of asyncPool(5, $('#newslist-top a[title]').slice(0, ctx.query.limit ? parseInt(ctx.query.limit) : 20), (item) => {
item = $(item);
const link = item.attr('href');
return ctx.cache.tryGet(link, async () => {
const response = await got(link);
const $ = cheerio.load(response.data);
const author = $('.artical-content p:eq(0)').text().trim();
$('.artical-content p:eq(0), .artical-content .flexbox').remove();
return {
title: item.attr('title'),
author,
description: $('.artical-content').html(),
category: $('meta[property="article:section"]').attr('content'),
pubDate: parseDate($('meta[property="article:published_time"]').attr('content')),
link,
};
});
})) {
items.push(data);
}
ctx.state.data = {
title: $('title').text(),
link: currentUrl,
description: $('meta[name="description"]').attr('content'),
item: items,
};
};

13
lib/v2/cts/radar.js Normal file
View File

@ -0,0 +1,13 @@
module.exports = {
'cts.com.tw': {
_name: '華視',
news: [
{
title: '新聞',
docs: 'https://docs.rsshub.app/traditional-media.html#hua-shi-xin-wen',
source: '/:category/index.html',
target: '/cts/:category',
},
],
},
};

3
lib/v2/cts/router.js Normal file
View File

@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/:category', require('./news'));
};