diff --git a/docs/README.md b/docs/README.md index d7579511f2..2dc011cad1 100755 --- a/docs/README.md +++ b/docs/README.md @@ -2422,6 +2422,8 @@ IATA 国际航空运输协会机场代码, 参见[维基百科 国际航空运 + + ### 小米 diff --git a/lib/router.js b/lib/router.js index 3ff476f861..32dc281740 100755 --- a/lib/router.js +++ b/lib/router.js @@ -374,6 +374,7 @@ router.get('/eztv/torrents/:imdb_id', require('./routes/eztv/imdb')); // 什么值得买 router.get('/smzdm/keyword/:keyword', require('./routes/smzdm/keyword')); router.get('/smzdm/ranking/:rank_type/:rank_id/:hour', require('./routes/smzdm/ranking')); +router.get('/smzdm/haowen/:day?', require('./routes/smzdm/haowen')); // 新京报 router.get('/bjnews/:cat', require('./routes/bjnews/news')); diff --git a/lib/routes/smzdm/haowen.js b/lib/routes/smzdm/haowen.js new file mode 100644 index 0000000000..6042fe9916 --- /dev/null +++ b/lib/routes/smzdm/haowen.js @@ -0,0 +1,62 @@ +const axios = require('../../utils/axios'); +const cheerio = require('cheerio'); +const date = require('../../utils/date'); + +module.exports = async (ctx) => { + const day = ctx.params.day || 'all'; + const link = `https://post.smzdm.com/hot_${day}`; + + const response = await axios.get(link); + const $ = cheerio.load(response.data); + const title = $('li.filter-tab.active').text(); + + const list = $('li.feed-row-wide') + .slice(0, 10) + .map(function() { + const info = { + title: $(this) + .find('h5.z-feed-title a') + .text(), + link: $(this) + .find('h5.z-feed-title a') + .attr('href'), + pubdate: $(this) + .find('span.z-publish-time') + .text(), + }; + return info; + }) + .get(); + + const out = await Promise.all( + list.map(async (info) => { + const title = info.title; + const pubdate = info.pubdate; + const itemUrl = info.link; + + const cache = await ctx.cache.get(itemUrl); + if (cache) { + return Promise.resolve(JSON.parse(cache)); + } + + const response = await axios.get(itemUrl); + const $ = cheerio.load(response.data); + const description = $('article > div').html(); + + const single = { + title: title, + link: itemUrl, + description: description, + pubDate: date(pubdate), + }; + ctx.cache.set(itemUrl, JSON.stringify(single), 24 * 60 * 60); + return Promise.resolve(single); + }) + ); + + ctx.state.data = { + title: `${title}-什么值得买好文`, + link: link, + item: out, + }; +};