Skip to content

Commit

Permalink
feat(router): ccac 澳门廉政公署 (#8273)
Browse files Browse the repository at this point in the history
Co-authored-by: Tony <[email protected]>
  • Loading branch information
linbuxiao and TonyRL authored Nov 27, 2021
1 parent daf95a4 commit 0edd6a7
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 5 deletions.
15 changes: 14 additions & 1 deletion docs/en/government.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,20 @@ pageClass: routes

### Press Releases

<Route author="linbuxiao" example="/icac/news/sc" path="/icac/news/:lang?" :paramsDesc="['Language, default to `sc`. Supprot `en`(English), `sc`(Simplified Chinese) and `tc`(Traditional Chinese)']">
<RouteEn author="linbuxiao" example="/icac/news/sc" path="/icac/news/:lang?" :paramsDesc="['Language, default to `sc`. Supprot `en`(English), `sc`(Simplified Chinese) and `tc`(Traditional Chinese)']"/>

## Macau Independent Commission Against Corruption

### Latest News

<RouteEn author="linbuxiao" example="/ccac/news/all" path="/ccac/news/:type/:lang?" :paramsDesc="['Category', 'Language, default to `sc`. Supprot `en`(English), `sc`(Simplified Chinese), `tc`(Traditional Chinese) and `pt`(Portuguese)']">
Category

| All | Detected Cases | Investigation Reports or Recommendations | Annual Reports | CCAC's Updates |
| ---- | -------------- | ----------------------------------------- | -------------- | -------------- |
| all | case | Persuasion | AnnualReport | PCANews |

</RouteEn>

## Ministry of Foreign Affairs of Japan

Expand Down
14 changes: 13 additions & 1 deletion docs/government.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,19 @@ pageClass: routes

### 新闻公布

<Route author="linbuxiao" example="/icac/news/sc" path="/icac/news/:lang?" :paramsDesc="['语言,留空为`sc`,支持`sc`(简中),`tc`(繁中),`en`(英文)']">
<Route author="linbuxiao" example="/icac/news/sc" path="/icac/news/:lang?" :paramsDesc="['语言,留空为`sc`,支持`sc`(简中),`tc`(繁中),`en`(英文)']"/>

## 澳门廉政公署

### 最新消息

<Route author="linbuxiao" example="/ccac/news/all" path="/ccac/news/:type/:lang?" :paramsDesc="['类别', '语言,留空为`sc`,支持`sc`(简中),`tc`(繁中),`en`(英文),`pt`(葡萄牙文)']">

| 全部 | 案件发布 | 调查报告或勘喻 | 年度报告 | 公署消息 |
| ---- | ------- | ------------ | ------------- | --------- |
| all | case | Persuasion | AnnualReport | PCANews |

</Route>

## 中国工业和信息化部

Expand Down
3 changes: 3 additions & 0 deletions lib/v2/ccac/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/news/:type/:lang?': ['linbuxiao'],
};
47 changes: 47 additions & 0 deletions lib/v2/ccac/news.js
Original file line number Diff line number Diff line change
@@ -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,
};
};
13 changes: 13 additions & 0 deletions lib/v2/ccac/radar.js
Original file line number Diff line number Diff line change
@@ -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',
},
],
},
};
3 changes: 3 additions & 0 deletions lib/v2/ccac/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/news/:type/:lang?', require('./news'));
};
32 changes: 32 additions & 0 deletions lib/v2/ccac/utils.js
Original file line number Diff line number Diff line change
@@ -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,
};
5 changes: 2 additions & 3 deletions lib/v2/icac/news.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')}`,
};
})
Expand All @@ -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;
Expand All @@ -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,
Expand Down

0 comments on commit 0edd6a7

Please sign in to comment.