From ce511b5b178891ebc4c4cab3f28797685c09afbc Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Wed, 9 Mar 2022 16:59:40 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E4=BF=84=E7=BD=97?= =?UTF-8?q?=E6=96=AF=E5=8D=AB=E6=98=9F=E9=80=9A=E8=AE=AF=E7=A4=BE=20(#9272?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(route): add 俄罗斯卫星通讯社 * fix: add radar --- docs/traditional-media.md | 12 +++++++ lib/v2/sputniknews/index.js | 59 ++++++++++++++++++++++++++++++++ lib/v2/sputniknews/maintainer.js | 3 ++ lib/v2/sputniknews/radar.js | 13 +++++++ lib/v2/sputniknews/router.js | 3 ++ 5 files changed, 90 insertions(+) create mode 100644 lib/v2/sputniknews/index.js create mode 100644 lib/v2/sputniknews/maintainer.js create mode 100644 lib/v2/sputniknews/radar.js create mode 100644 lib/v2/sputniknews/router.js diff --git a/docs/traditional-media.md b/docs/traditional-media.md index 60120964c..63398ee96 100644 --- a/docs/traditional-media.md +++ b/docs/traditional-media.md @@ -766,6 +766,18 @@ Type 栏目: +## 俄罗斯卫星通讯社 + +### 分类 + + + +| 新闻 | 中国 | 俄罗斯 | 国际 | 俄中关系 | 评论 | +| ---- | ----- | ------ | -------------- | ---------------------- | ------- | +| news | china | russia | category_guoji | russia_china_relations | opinion | + + + ## 公視新聞網 ### 即時新聞 diff --git a/lib/v2/sputniknews/index.js b/lib/v2/sputniknews/index.js new file mode 100644 index 000000000..362d89099 --- /dev/null +++ b/lib/v2/sputniknews/index.js @@ -0,0 +1,59 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const category = ctx.params.category ?? 'news'; + + const rootUrl = 'https://sputniknews.cn'; + const currentUrl = `${rootUrl}/services/${category}/more.html`; + + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + let items = $('.list__title') + .toArray() + .map((item) => { + item = $(item); + + return { + title: item.text(), + link: `${rootUrl}${item.attr('href')}`, + }; + }); + + items = await Promise.all( + items.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + + const content = cheerio.load(detailResponse.data); + + item.category = content('.tag__text') + .toArray() + .map((tag) => content(tag).text()); + + content('.article__meta, .article__title, .article__info, .article__quote-bg, .article__footer, .m-buy, .photoview__ext-link').remove(); + content('div[data-type="article"]').remove(); + + item.description = content('.article').html(); + item.pubDate = parseDate(content('div[itemprop="datePublished"]').attr('data-unixtime')); + + return item; + }) + ) + ); + + ctx.state.data = { + title: `${category} - 俄罗斯卫星通讯社`, + link: `${rootUrl}/${category}`, + item: items, + }; +}; diff --git a/lib/v2/sputniknews/maintainer.js b/lib/v2/sputniknews/maintainer.js new file mode 100644 index 000000000..81eb78d73 --- /dev/null +++ b/lib/v2/sputniknews/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/:category?': ['nczitzk'], +}; diff --git a/lib/v2/sputniknews/radar.js b/lib/v2/sputniknews/radar.js new file mode 100644 index 000000000..c3bae5fed --- /dev/null +++ b/lib/v2/sputniknews/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'sputniknews.cn': { + _name: '俄罗斯卫星通讯社', + '.': [ + { + title: '分类', + docs: 'https://docs.rsshub.app/traditional-media.html#e-luo-si-wei-xing-tong-xun-she-fen-lei', + source: ['/:category', '/'], + target: '/sputniknews/:category', + }, + ], + }, +}; diff --git a/lib/v2/sputniknews/router.js b/lib/v2/sputniknews/router.js new file mode 100644 index 000000000..cf781366f --- /dev/null +++ b/lib/v2/sputniknews/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/:category?', require('./index')); +};