diff --git a/docs/other.md b/docs/other.md index b509bde5e4..556bebe718 100644 --- a/docs/other.md +++ b/docs/other.md @@ -505,6 +505,10 @@ type 为 all 时,category 参数不支持 cost 和 free +## 福利资源-met.red + + + ## 毕马威 diff --git a/lib/router.js b/lib/router.js index 1de2734b06..4e7670b1a5 100755 --- a/lib/router.js +++ b/lib/router.js @@ -1297,6 +1297,9 @@ router.get('/mlhang', require('./routes/mlhang/latest')); // PlayStation Store router.get('/ps/list/:gridName', require('./routes/ps/list')); +// 福利资源-met.red +router.get('/metred/fuli', require('./routes/metred/fuli')); + // MIT router.get('/mit/graduateadmissions/:type/:name', require('./routes/universities/mit/graduateadmissions')); diff --git a/lib/routes/metred/fuli.js b/lib/routes/metred/fuli.js new file mode 100644 index 0000000000..0888da9e10 --- /dev/null +++ b/lib/routes/metred/fuli.js @@ -0,0 +1,56 @@ +const axios = require('../../utils/axios'); +const host = 'https://met.red'; +const mainPage = 'https://met.red/h/weal/list#'; +const cheerio = require('cheerio'); +const url = require('url'); + +async function load(link, ctx) { + const cache = await ctx.cache.get(link); + if (cache) { + return cache; + } + const response = await axios.get(link); + const $ = cheerio.load(response.data); + const images = $('img'); + for (let k = 0; k < images.length; k++) { + $(images[k]).replaceWith(``); + } + const couponUrl = $('.layui-btn.layui-btn.layui-btn-lg').attr('href'); + let eventHtml; + if (!couponUrl || couponUrl === undefined) { + eventHtml = '

活动链接:无

'; + } else { + eventHtml = `
点我前往活动
`; + } + const description = eventHtml + $('.p-detail-html').html(); + await ctx.cache.set(link, description); + return { description }; +} + +module.exports = async (ctx) => { + const response = await axios({ + method: 'get', + url: mainPage, + }); + const data = response.data; + const $ = cheerio.load(data); + const list = $('h4 > a').get(); + const process = await Promise.all( + list.map(async (item) => { + const itemUrl = host + $(item).attr('href'); + const single = { + title: $(item).text(), + link: itemUrl, + guid: itemUrl, + }; + const other = await load(itemUrl, ctx); + return Promise.resolve(Object.assign({}, single, other)); + }) + ); + ctx.state.data = { + title: '福利资源-met.red', + link: mainPage, + description: '福利资源更新提醒', + item: process, + }; +};