From 0edd6a7387cc7f354ef021f9bb8f36a811260892 Mon Sep 17 00:00:00 2001 From: linbuxiao <56839018+linbuxiao@users.noreply.github.com> Date: Sat, 27 Nov 2021 15:55:16 +0800 Subject: [PATCH] =?UTF-8?q?feat(router):=20ccac=20=E6=BE=B3=E9=97=A8?= =?UTF-8?q?=E5=BB=89=E6=94=BF=E5=85=AC=E7=BD=B2=20(#8273)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Tony --- docs/en/government.md | 15 ++++++++++++- docs/government.md | 14 +++++++++++- lib/v2/ccac/maintainer.js | 3 +++ lib/v2/ccac/news.js | 47 +++++++++++++++++++++++++++++++++++++++ lib/v2/ccac/radar.js | 13 +++++++++++ lib/v2/ccac/router.js | 3 +++ lib/v2/ccac/utils.js | 32 ++++++++++++++++++++++++++ lib/v2/icac/news.js | 5 ++--- 8 files changed, 127 insertions(+), 5 deletions(-) create mode 100644 lib/v2/ccac/maintainer.js create mode 100644 lib/v2/ccac/news.js create mode 100644 lib/v2/ccac/radar.js create mode 100644 lib/v2/ccac/router.js create mode 100644 lib/v2/ccac/utils.js diff --git a/docs/en/government.md b/docs/en/government.md index c472b0fdc74ffa..970ded0d9d9110 100644 --- a/docs/en/government.md +++ b/docs/en/government.md @@ -20,7 +20,20 @@ pageClass: routes ### Press Releases - + + +## Macau Independent Commission Against Corruption + +### Latest News + + +Category + +| All | Detected Cases | Investigation Reports or Recommendations | Annual Reports | CCAC's Updates | +| ---- | -------------- | ----------------------------------------- | -------------- | -------------- | +| all | case | Persuasion | AnnualReport | PCANews | + + ## Ministry of Foreign Affairs of Japan diff --git a/docs/government.md b/docs/government.md index a2373cfa8355aa..7965cc37a05f3c 100644 --- a/docs/government.md +++ b/docs/government.md @@ -250,7 +250,19 @@ pageClass: routes ### 新闻公布 - + + +## 澳门廉政公署 + +### 最新消息 + + + +| 全部 | 案件发布 | 调查报告或勘喻 | 年度报告 | 公署消息 | +| ---- | ------- | ------------ | ------------- | --------- | +| all | case | Persuasion | AnnualReport | PCANews | + + ## 中国工业和信息化部 diff --git a/lib/v2/ccac/maintainer.js b/lib/v2/ccac/maintainer.js new file mode 100644 index 00000000000000..f913c0558d653b --- /dev/null +++ b/lib/v2/ccac/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/news/:type/:lang?': ['linbuxiao'], +}; diff --git a/lib/v2/ccac/news.js b/lib/v2/ccac/news.js new file mode 100644 index 00000000000000..3cd3c795c88abe --- /dev/null +++ b/lib/v2/ccac/news.js @@ -0,0 +1,47 @@ +const utils = require('./utils'); +const { parseDate } = require('@/utils/parse-date'); +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const browser = await require('@/utils/puppeteer')(); + const lang = ctx.params.lang ?? 'sc'; + const type = utils.TYPE[ctx.params.type]; + + const BASE = utils.langBase(lang); + const page = await browser.newPage(); + await page.goto(BASE); + const articles = await page.evaluate(() => window.articles); + + const list = utils + .typeFilter(articles, type) + .slice(0, 11) + .map((item) => ({ + title: item.name, + category: item.tags.map((tag) => tag.name).join(','), + link: utils.BASE_URL + item.url, + pubDate: parseDate(item.time, 'YYYY-MM-DD'), + })); + const items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + + const $ = cheerio.load(detailResponse.data); + $('.article_details_body > *').removeAttr('style'); + item.description = $('.article_details_body').html(); + return item; + }) + ) + ); + ctx.state.data = { + title: `CCAC ${type}`, + link: BASE, + description: `CCAC ${type}`, + language: ctx.params.lang ? utils.LANG_TYPE[ctx.params.lang] : utils.LANG_TYPE.sc, + item: items, + }; +}; diff --git a/lib/v2/ccac/radar.js b/lib/v2/ccac/radar.js new file mode 100644 index 00000000000000..6bd1edec8bfa1b --- /dev/null +++ b/lib/v2/ccac/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'ccac.org.mo': { + _name: '澳门廉政公署', + '.': [ + { + title: '最新消息', + docs: 'https://docs.rsshub.app/government.html#ao-men-lian-zheng-gong-shu', + source: ['/:lang/news.html'], + target: '/ccac/news/all/:lang', + }, + ], + }, +}; diff --git a/lib/v2/ccac/router.js b/lib/v2/ccac/router.js new file mode 100644 index 00000000000000..8833f9390a2e61 --- /dev/null +++ b/lib/v2/ccac/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/news/:type/:lang?', require('./news')); +}; diff --git a/lib/v2/ccac/utils.js b/lib/v2/ccac/utils.js new file mode 100644 index 00000000000000..fe061025a0a7bf --- /dev/null +++ b/lib/v2/ccac/utils.js @@ -0,0 +1,32 @@ +const BASE_URL = 'https://www.ccac.org.mo'; + +const LANG_TYPE = { + en: 'en-us', + sc: 'zh-cn', + tc: 'zh-hk', + pt: 'pt', +}; + +const TYPE = { + all: '全部', + case: '案件發佈', + Persuasion: '調查報告或勸喻', + AnnualReport: '年度報告', + PCANews: '公署消息', +}; + +function langBase(lang) { + return `${BASE_URL}/${lang}/news.html`; +} + +function typeFilter(list, type) { + return type === '全部' ? list : list.filter((item) => item.tags.some((tag) => tag.name === type)); +} + +module.exports = { + TYPE, + BASE_URL, + LANG_TYPE, + langBase, + typeFilter, +}; diff --git a/lib/v2/icac/news.js b/lib/v2/icac/news.js index 4fde059ae97699..8744b56ebf1d37 100644 --- a/lib/v2/icac/news.js +++ b/lib/v2/icac/news.js @@ -11,8 +11,8 @@ module.exports = async (ctx) => { const list = $('.pressItem.clearfix') .map((_, e) => { const c = cheerio.load(e); - return { + title: c('.hd a').text(), link: `${utils.BASE_URL}${c('.hd a').attr('href')}`, }; }) @@ -30,7 +30,6 @@ module.exports = async (ctx) => { c('.col-3-wrap.clearfix.pressPhoto div').removeAttr('class'); const des = c('.pressContent.full').html(); const thumbs = c('.col-3-wrap.clearfix.pressPhoto').html() ?? ''; - item.title = c('h2').text().trim(); item.pubDate = parseDate(decodeURI(c('.date').text().trim()), ['YYYY年MM月DD日', 'YYYY年MM月D日', 'YYYY年M月DD日', 'YYYY年M月D日'], true); item.description = des + thumbs; return item; @@ -39,7 +38,7 @@ module.exports = async (ctx) => { ); ctx.state.data = { title: 'ICAC 新闻公布', - link: 'https://www.icac.org.hk/tc/press/index.html', + link: `${BASE_WITH_LANG}/press/index.html`, description: 'ICAC 新闻公布', language: ctx.params.lang ? utils.LANG_TYPE[ctx.params.lang] : utils.LANG_TYPE.sc, item: items,