diff --git a/docs/en/government.md b/docs/en/government.md index 6e91cf89ce..eb9f9e8d33 100644 --- a/docs/en/government.md +++ b/docs/en/government.md @@ -4,6 +4,12 @@ pageClass: routes # Goverment +## Ministry of Foreign Affairs of Japan + +### Press conference + + + ## United Nations ### Security Council Vetoed a Resolution diff --git a/docs/government.md b/docs/government.md index 6c73d00951..38f10a91b0 100644 --- a/docs/government.md +++ b/docs/government.md @@ -71,6 +71,12 @@ pageClass: routes +## 日本国外務省 + +### 記者会見 + + + ## 苏州市人民政府 ### 政府新闻 diff --git a/lib/router.js b/lib/router.js index 2a3a3d363d..e2761a9aa4 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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')); diff --git a/lib/routes/go.jp/mofa/main.js b/lib/routes/go.jp/mofa/main.js new file mode 100644 index 0000000000..4ed0ba2c63 --- /dev/null +++ b/lib/routes/go.jp/mofa/main.js @@ -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() + '
' + $('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, + }; +};