fix: macau government 2019-ncov news new json data source (#3925)

This commit is contained in:
KeiLongW 2020-02-09 19:18:24 +08:00 committed by GitHub
parent a7801876fa
commit a89893e876
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 33 deletions

View File

@ -3,49 +3,35 @@ const cheerio = require('cheerio');
module.exports = async (ctx) => {
const language = ctx.params.lang.toLowerCase();
const languageKey = language === 'ch' ? 'zhant' : language;
const dataUrl = `https://www.ssm.gov.mo/apps1/apps/webpage2020/wpg/gcsnewssc_body.aspx`;
const dateTextMapping = {
ch: '日期 : ',
pt: 'Date : ',
en: 'Date : ',
};
const dataUrl = 'https://gcloud.gcs.gov.mo/json/ncvbase.json';
const response = await got({
method: 'post',
method: 'get',
url: dataUrl,
form: {
pg: '0',
lang: language,
},
});
const $ = cheerio.load(response.data);
const items = $('div.col-xs-12')
.map((i, elem) => {
const $item = cheerio.load(elem);
const title = $item('div > span.padding-sm > b > a:first-child').text();
const $descriptionWrapper = cheerio.load('<div></div>');
$descriptionWrapper('div').append(
$item('div.clearfix')
.first()
.nextAll()
);
const description = $descriptionWrapper.html();
const pubDate = new Date(
$descriptionWrapper('div.padding-sm.fontsize-sm')
.text()
.replace(dateTextMapping[language], '') + ' +8'
).toUTCString();
const link = $item('div > span.padding-sm > b > a:first-child').attr('href');
const items = response.data.json
.filter((item) => item['broadcastStatus_' + languageKey] === 'Broadcasted')
.slice(0, 20)
.map((item) => {
const title = item['subject_' + languageKey];
const $ = cheerio.load('<div id="root"><b id="department"></b><div id="photo"></div><div id="content"></div></div>');
if (item.contentPhotos) {
$('#photo').append(item.contentPhotos.map((photo) => `<img src="${photo.url}"></img>`));
}
$('#content').append(item['content_' + languageKey]);
$('#department').append(item['departments_' + languageKey]);
const description = $('#root').html();
const pubDate = new Date(item['broadcastTime_' + languageKey] + ' +8').toUTCString();
const link = item['url_' + languageKey];
return {
title,
description,
pubDate,
link,
};
})
.get();
});
const titleMapping = {
ch: '澳門特別行政區政府 抗疫專頁:最新消息',