diff --git a/docs/travel.md b/docs/travel.md index 795381e83a..1fe24de187 100644 --- a/docs/travel.md +++ b/docs/travel.md @@ -102,6 +102,14 @@ IATA 国际航空运输协会机场代码,参见[维基百科 国际航空运 +### 自由行 + + + +目的地代码请参见 [这里](http://www.mafengwo.cn/mdd/) + + + ## 中国美术馆 ### 美术馆新闻 diff --git a/lib/router.js b/lib/router.js index a518b0bcf1..6cf467481a 100644 --- a/lib/router.js +++ b/lib/router.js @@ -517,6 +517,7 @@ router.get('/hopper/:lowestOnly/:from/:to?', require('./routes/hopper/index')); // 马蜂窝 router.get('/mafengwo/note/:type', require('./routes/mafengwo/note')); +router.get('/mafengwo/ziyouxing/:code', require('./routes/mafengwo/ziyouxing')); // 中国地震局震情速递(与地震台网同步更新) router.get('/earthquake/:region?', require('./routes/earthquake')); diff --git a/lib/routes/mafengwo/ziyouxing.js b/lib/routes/mafengwo/ziyouxing.js new file mode 100644 index 0000000000..13a44cf0d9 --- /dev/null +++ b/lib/routes/mafengwo/ziyouxing.js @@ -0,0 +1,49 @@ +const url = require('url'); +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const rootUrl = `http://www.mafengwo.cn/gonglve/ziyouxing/list/list_page?mddid=${ctx.params.code}&page=1`; + + const response = await got({ + method: 'get', + url: rootUrl, + }); + const $ = cheerio.load(response.data.html); + const list = $('div.item') + .slice(0, 10) + .map((_, item) => { + item = $(item); + const a = item.find('a'); + return { + title: item.find('h3').text(), + link: url.resolve(`http://www.mafengwo.cn`, a.attr('href')), + }; + }) + .get(); + + const items = await Promise.all( + list.map( + async (item) => + await ctx.cache.tryGet(item.link, async () => { + const res = await got({ method: 'get', url: item.link }); + const content = cheerio.load(res.data); + item.pubDate = new Date(content('span.time').eq(1).find('em').text()).toUTCString(); + item.description = content('div.sideL').html(); + return item; + }) + ) + ); + + const titleResponse = await got({ + method: 'get', + url: `http://www.mafengwo.cn/gonglve/ziyouxing/mdd_${ctx.params.code}/`, + }); + const title = cheerio.load(titleResponse.data); + + ctx.state.data = { + title: title('title').text(), + link: rootUrl, + item: items, + }; +};