feat: Japan MFA, Press conference (#5452)

日本国外務省記者会見
This commit is contained in:
sgqy
2020-08-18 20:58:45 +01:00
committed by GitHub
parent 8a726219e8
commit 53ec35a225
4 changed files with 110 additions and 0 deletions
+6
View File
@@ -4,6 +4,12 @@ pageClass: routes
# Goverment
## Ministry of Foreign Affairs of Japan
### Press conference
<RouteEn author="sgqy" example="/go.jp/mofa" path="/go.jp/mofa"/>
## United Nations
### Security Council Vetoed a Resolution
+6
View File
@@ -71,6 +71,12 @@ pageClass: routes
<Route author="HenryQW" example="/un/scveto" path="/un/scveto"/>
## 日本国外務省
### 記者会見
<Route author="sgqy" example="/go.jp/mofa" path="/go.jp/mofa"/>
## 苏州市人民政府
### 政府新闻
+3
View File
@@ -1258,6 +1258,9 @@ router.get('/gov/beijing/bjeea/:type', require('./routes/gov/beijing/eea'));
// 广东省教育厅
router.get('/gov/guangdong/edu/:caty', require('./routes/gov/guangdong/edu'));
// 日本国外務省記者会見
router.get('/go.jp/mofa', require('./routes/go.jp/mofa/main'));
// 小黑盒
router.get('/xiaoheihe/user/:id', require('./routes/xiaoheihe/user'));
router.get('/xiaoheihe/news', require('./routes/xiaoheihe/news'));
+95
View File
@@ -0,0 +1,95 @@
// Japan government page
// params:
// [null]
const got = require('@/utils/got'); // get web content
const cheerio = require('cheerio'); // html parser
const path = require('path');
const base_url = 'https://www.mofa.go.jp';
const index_url = path.join(base_url, '/mofaj/press/kaiken/bn/index.html');
module.exports = async (ctx) => {
// get the update list
const response = await got({
method: 'get',
url: index_url,
});
const data = response.data; // content is html format
const $ = cheerio.load(data);
const list = $('dl.title-list dt.list-title a');
// parse meeting urls
const detail_urls = [];
for (let i = 0; i < list.length; ++i) {
// for (let i = 0; i < 1; ++i) {
const a = list[i];
if ($(a).text() === 'テキスト版要旨') {
let l = $(a).attr('href');
l = path.join(base_url, l);
detail_urls.push(l);
}
}
// get meetings
const responses = await Promise.all(detail_urls.map((url) => got(url)));
const meetings = responses.map(({ data }) => data);
// get real data to feed
const article_list = [];
for (let i = 0; i < meetings.length; ++i) {
const $ = cheerio.load(meetings[i]);
$('script').remove();
$('div.social-btn-top').remove();
const link = $('meta[property="og:url"]').attr('content');
const title = $('meta[property="og:title"]').attr('content');
const author = '外務省';
const content = $('h3.title3').html() + '<br/>' + $('div#maincontents').html();
let pub_date_num = '1970-01-01T00:00Z';
try {
const date_str = $('h3.title3').text();
const m = date_str.match(/((..)([0-9]+)年([0-9]+)月([0-9]+)日((.)曜日)([0-9]+)時([0-9]+)分.*)/);
const era = m[1];
let yy = parseInt(m[2]);
const mm = m[3];
const dd = m[4];
// const ww = m[5];
const HH = m[6];
const MM = m[7];
switch (era) {
case '昭和':
yy += 1925;
break;
case '平成':
yy += 1988;
break;
case '令和':
yy += 2018;
break;
}
pub_date_num = yy.toString() + '-' + mm + '-' + dd + ' ' + HH + ':' + MM + ' +09';
// console.log(pub_date_num);
} catch (_) {
_;
}
const pub_date = new Date(pub_date_num).toUTCString();
const item = {
title: title,
author: author,
pubDate: pub_date,
link: link,
description: content,
};
article_list.push(item);
}
// feed the data
ctx.state.data = {
title: '日本国外務省記者会見',
link: index_url,
item: article_list,
};
};