From d251822d5193795d4d264ef920bb0c679686d997 Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Sat, 27 Nov 2021 16:47:01 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E5=85=AC=E8=A6=96?= =?UTF-8?q?=E6=96=B0=E8=81=9E=E7=B6=B2=E5=8D=B3=E6=99=82=E6=96=B0=E8=81=9E?= =?UTF-8?q?=20(#8458)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/traditional-media.md | 6 +++++ docs/traditional-media.md | 6 +++++ lib/v2/pts/dailynews.js | 52 ++++++++++++++++++++++++++++++++++++ lib/v2/pts/maintainer.js | 3 +++ lib/v2/pts/radar.js | 13 +++++++++ lib/v2/pts/router.js | 3 +++ 6 files changed, 83 insertions(+) create mode 100644 lib/v2/pts/dailynews.js create mode 100644 lib/v2/pts/maintainer.js create mode 100644 lib/v2/pts/radar.js create mode 100644 lib/v2/pts/router.js diff --git a/docs/en/traditional-media.md b/docs/en/traditional-media.md index 2ead21d00..956f86f9b 100644 --- a/docs/en/traditional-media.md +++ b/docs/en/traditional-media.md @@ -430,3 +430,9 @@ Provide full article RSS for WSJ topics. Provides all of the articles by the specified Yahoo! author. + +## 公視新聞網 + +### Daily News + + \ No newline at end of file diff --git a/docs/traditional-media.md b/docs/traditional-media.md index c25f3f79e..b77d8aa77 100644 --- a/docs/traditional-media.md +++ b/docs/traditional-media.md @@ -699,6 +699,12 @@ Type 栏目: +## 公視新聞網 + +### 即時新聞 + + + ## 华尔街见闻 ### 华尔街见闻 diff --git a/lib/v2/pts/dailynews.js b/lib/v2/pts/dailynews.js new file mode 100644 index 000000000..8eb7d47f8 --- /dev/null +++ b/lib/v2/pts/dailynews.js @@ -0,0 +1,52 @@ +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://news.pts.org.tw'; + const currentUrl = `${rootUrl}/dailynews`; + + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + const list = $('h2 a') + .map((_, item) => { + item = $(item); + + return { + title: item.text(), + link: item.attr('href'), + }; + }) + .get(); + + 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.author = content('meta[property="article:author"]').attr('content'); + item.pubDate = timezone(parseDate(content('meta[property="article:published_time"]').attr('content')), +8); + item.description = `${content('.post-article').html()}`; + + return item; + }) + ) + ); + + ctx.state.data = { + title: '即時 | 公視新聞網 PNN', + link: currentUrl, + item: items, + }; +}; diff --git a/lib/v2/pts/maintainer.js b/lib/v2/pts/maintainer.js new file mode 100644 index 000000000..8eaa4e035 --- /dev/null +++ b/lib/v2/pts/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/dailynews': ['nczitzk'], +}; diff --git a/lib/v2/pts/radar.js b/lib/v2/pts/radar.js new file mode 100644 index 000000000..a5ff8e2bd --- /dev/null +++ b/lib/v2/pts/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'pts.org.tw': { + _name: '公視新聞網 PNN', + news: [ + { + title: '即時', + docs: 'https://docs.rsshub.app/traditional-media.html#gong-shi-xin-wen-wang-ji-shi-xin-wen', + source: ['/dailynews'], + target: '/pts/dailynews', + }, + ], + }, +}; diff --git a/lib/v2/pts/router.js b/lib/v2/pts/router.js new file mode 100644 index 000000000..e2bb9b13d --- /dev/null +++ b/lib/v2/pts/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/dailynews', require('./dailynews')); +};