From bf0ecf0ae9b9bf5a5c9d063b78ff55b1e41484da Mon Sep 17 00:00:00 2001 From: Henry Wang Date: Mon, 28 Jan 2019 10:13:16 +0000 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=BE=AE=E4=BF=A1=E5=85=AC?= =?UTF-8?q?=E4=BC=97=E5=8F=B7=20wemp.app=20=E8=B7=AF=E5=BE=84=20(#1469)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 ++ lib/router.js | 1 + lib/routes/tencent/wechat/wemp.js | 50 +++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 lib/routes/tencent/wechat/wemp.js diff --git a/docs/README.md b/docs/README.md index e3a9db33d..bce2b6e17 100644 --- a/docs/README.md +++ b/docs/README.md @@ -391,6 +391,8 @@ RSSHub 提供下列 API 接口: + + diff --git a/lib/router.js b/lib/router.js index db0a0fe84..581b1ea9a 100644 --- a/lib/router.js +++ b/lib/router.js @@ -497,6 +497,7 @@ router.get('/bugly/changelog/:platform', require('./routes/tencent/bugly/changel // wechat router.get('/wechat/wasi/:id', require('./routes/tencent/wechat/wasi')); +router.get('/wechat/wemp/:id', require('./routes/tencent/wechat/wemp')); router.get('/wechat/announce', require('./routes/tencent/wechat/announce')); router.get('/wechat/miniprogram/plugins', require('./routes/tencent/wechat/miniprogram/plugins')); diff --git a/lib/routes/tencent/wechat/wemp.js b/lib/routes/tencent/wechat/wemp.js new file mode 100644 index 000000000..07f850bb7 --- /dev/null +++ b/lib/routes/tencent/wechat/wemp.js @@ -0,0 +1,50 @@ +const axios = require('../../../utils/axios'); +const cheerio = require('cheerio'); +// const timezone = require('../../utils/timezone'); + +module.exports = async (ctx) => { + const { id } = ctx.params; + + const response = await axios.get(`https://wemp.app/accounts/${id}`); + + const $ = cheerio.load(response.data); + const author = $('.mp-info__title') + .text() + .trim(); + + const year = new Date().getFullYear(); + const items = $('.post-item__main') + .slice(0, 10) + .get() + .map((e) => ({ + title: $(e) + .find('.post-item__title') + .text() + .trim(), + link: `https://wemp.app${$(e) + .find('.post-item__title') + .attr('href')}`, + pubDate: timezone( + `${year} ${$(e) + .find('.post-item__date') + .text() + .trim()}`, + 8 + ), + author, + })); + + // to be replaced + function timezone(html, timezone) { + return new Date(new Date(html).getTime() - 60 * 60 * 1000 * (timezone + new Date().getTimezoneOffset() / 60)).toUTCString(); + } + + ctx.state.data = { + title: `微信公众号 - ${author}`, + link: `https://wemp.app/accounts/${id}/`, + description: $('.mp-info__value') + .text() + .trim(), + item: items, + }; +};