From f083bf4e49e828c283021e8910f754198eb199ce Mon Sep 17 00:00:00 2001 From: Tim Wu <15276630+TimWu007@users.noreply.github.com> Date: Fri, 24 Mar 2023 21:48:37 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20Add=20=E5=B9=BF=E5=B7=9E?= =?UTF-8?q?=E6=97=A5=E6=8A=A5=E5=AE=A2=E6=88=B7=E7=AB=AF=E3=80=81=E6=96=B0?= =?UTF-8?q?=E8=8A=B1=E5=9F=8E=20(#12162)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(route): add Guangzhou Daily (APP) 广州日报(客户端) * feat(route): Add 新花城(广州市融媒体中心) * Update lib/v2/gzdaily/app.js * Update lib/v2/gzdaily/cmc.js * Update lib/v2/gzdaily/cmc.js * Update lib/v2/gzdaily/router.js * Update lib/v2/gzdaily/maintainer.js * Update docs/traditional-media.md * Update docs/traditional-media.md * Update lib/v2/gzdaily/radar.js * Update lib/v2/gzdaily/radar.js * Update lib/v2/gzdaily/app.js * Update gzdaily --------- --- docs/traditional-media.md | 36 ++++++++++++++ lib/v2/gzdaily/app.js | 53 +++++++++++++++++++++ lib/v2/gzdaily/cmc.js | 60 ++++++++++++++++++++++++ lib/v2/gzdaily/maintainer.js | 4 ++ lib/v2/gzdaily/radar.js | 22 +++++++++ lib/v2/gzdaily/router.js | 4 ++ lib/v2/gzdaily/templates/description.art | 3 ++ 7 files changed, 182 insertions(+) create mode 100644 lib/v2/gzdaily/app.js create mode 100644 lib/v2/gzdaily/cmc.js create mode 100644 lib/v2/gzdaily/maintainer.js create mode 100644 lib/v2/gzdaily/radar.js create mode 100644 lib/v2/gzdaily/router.js create mode 100644 lib/v2/gzdaily/templates/description.art diff --git a/docs/traditional-media.md b/docs/traditional-media.md index d653ba89c..0bea91efe 100644 --- a/docs/traditional-media.md +++ b/docs/traditional-media.md @@ -1083,6 +1083,42 @@ IT・科学 tech_science +## 广州日报 + +### 客户端 + + + +::: tip 提示 + +在北京时间深夜可能无法获取内容。 + +::: + +常用栏目 ID: + +| 栏目名 | ID | +| ------ | ---- | +| 首页 | 74 | +| 时局 | 374 | +| 广州 | 371 | +| 大湾区 | 397 | +| 城区 | 2980 | + + + +### 新花城(广州市融媒体中心) + + + +::: tip 提示 + +`频道名(channel)` 可在对应频道 url 后的参数中获取,如 `首页` 的栏目 url 为`https://huacheng.gz-cmc.com/channel/shouye/index.html`, `频道名` 即为 `shouye`。 + +::: + + + ## 国际金融报栏目 ### 栏目 diff --git a/lib/v2/gzdaily/app.js b/lib/v2/gzdaily/app.js new file mode 100644 index 000000000..ad790a3c3 --- /dev/null +++ b/lib/v2/gzdaily/app.js @@ -0,0 +1,53 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const timezone = require('@/utils/timezone'); +const { parseDate } = require('@/utils/parse-date'); +const { art } = require('@/utils/render'); +const path = require('path'); + +module.exports = async (ctx) => { + const column = ctx.params.column ?? 74; + const currentUrl = `https://app.gzdaily.cn/app_if/getArticles?columnId=${column}&page=1`; + + const { data: response } = await got(currentUrl); + + const list = response.list + .filter((i) => i.newstype === 0) // Remove special report (专题) and articles from Guangzhou Converged Media Center (新花城). + .map((item) => ({ + title: item.title, + description: art(path.join(__dirname, 'templates/description.art'), { + thumb: item.picBig, + }), + pubDate: timezone(parseDate(item.publishtime), +8), + link: item.shareUrl, + colName: item.colName, + author: item.arthorName, + })); + + let colName = ''; + + 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); + colName = colName === '' ? item.colName : colName; + if (content('.abstract').text()) { + content('.abstract').find('span').remove(); + item.description += '
' + content('.abstract').text() + '
'; + } + item.description += content('.article').html() ?? ''; + return item; + }) + ) + ); + + ctx.state.data = { + title: `广州日报客户端 - ${colName}`, + link: `https://www.gzdaily.cn/amucsite/web/index.html#/home/${column}`, + item: items, + }; +}; diff --git a/lib/v2/gzdaily/cmc.js b/lib/v2/gzdaily/cmc.js new file mode 100644 index 000000000..98f2880be --- /dev/null +++ b/lib/v2/gzdaily/cmc.js @@ -0,0 +1,60 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const timezone = require('@/utils/timezone'); +const { parseDate } = require('@/utils/parse-date'); +const { art } = require('@/utils/render'); +const path = require('path'); + +module.exports = async (ctx) => { + const channel = ctx.params.channel ?? 'shouye'; + const currentUrl = `https://huacheng.gz-cmc.com/channel/${channel}/index.html`; + + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + const title = $('a.brand').text().trim(); + let items = $('.news-list-row2') + .toArray() + .filter((item) => $(item).attr('contenttype') === '1' && $(item).attr('mlistpattern') === '1') + .map((item) => { + item = $(item); + return { + title: item.text().replace(/\s*/g, ''), + link: item.children('a').attr('href'), + description: art(path.join(__dirname, 'templates/description.art'), { + thumb: item.find('img').attr('src'), + }), + }; + }); + + 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); + content('.broadcast-container').remove(); + + item.description += content('.article-source').html() ?? ''; + item.description += content('#articleContent').html(); + item.title = content('title').text(); + item.author = content('meta[name="author"]').attr('content'); + item.pubDate = timezone(parseDate(content('.article-time').text()), +8); + + return item; + }) + ) + ); + + ctx.state.data = { + title: `广州日报新花城 - ${title}`, + link: currentUrl, + item: items, + }; +}; diff --git a/lib/v2/gzdaily/maintainer.js b/lib/v2/gzdaily/maintainer.js new file mode 100644 index 000000000..67adb75ff --- /dev/null +++ b/lib/v2/gzdaily/maintainer.js @@ -0,0 +1,4 @@ +module.exports = { + '/app/:column?': ['TimWu007'], + '/cmc/:channel?': ['TimWu007'], +}; diff --git a/lib/v2/gzdaily/radar.js b/lib/v2/gzdaily/radar.js new file mode 100644 index 000000000..638a5f826 --- /dev/null +++ b/lib/v2/gzdaily/radar.js @@ -0,0 +1,22 @@ +module.exports = { + 'gzdaily.cn': { + _name: '广州日报', + '.': [ + { + title: '客户端', + docs: 'https://docs.rsshub.app/traditional-media.html#guang-zhou-ri-bao', + source: ['/'], + }, + ], + }, + 'gz-cmc.com': { + _name: '广州日报', + huacheng: [ + { + title: '新花城(广州市融媒体中心)', + docs: 'https://docs.rsshub.app/traditional-media.html#guang-zhou-ri-bao', + source: ['/'], + }, + ], + }, +}; diff --git a/lib/v2/gzdaily/router.js b/lib/v2/gzdaily/router.js new file mode 100644 index 000000000..578df19de --- /dev/null +++ b/lib/v2/gzdaily/router.js @@ -0,0 +1,4 @@ +module.exports = (router) => { + router.get('/app/:column?', require('./app')); + router.get('/cmc/:channel?', require('./cmc')); +}; diff --git a/lib/v2/gzdaily/templates/description.art b/lib/v2/gzdaily/templates/description.art new file mode 100644 index 000000000..2113e7063 --- /dev/null +++ b/lib/v2/gzdaily/templates/description.art @@ -0,0 +1,3 @@ +{{ if thumb }} +
+{{ /if }} \ No newline at end of file