增加:微信公众平台-系统公告栏目 (#895)

- 实现 #883 
- 没找到比较合适的分类,暂时先放到`程序更新`下面
- 由于正文内容是放在 `window.wxCgi` 中,输出的话需要出动 `puppeteer` 来搞,感觉意义不太大而且资源消耗也大,所以暂时未输出正文内容。后续如有需要再添加(其实用正则去匹配也不是不行(光速逃
- 最后有个疑问点:爬取到的链接中有这样的`https://mp.weixin.qq.com/cgi-bin/announce?action=getannouncement&announce_id=11531387046zmIME&version=&lang=zh_CN`,中间带有`&`这类特殊符号,试了下发现输出为 `json` 格式时会转义掉变成这样`https://mp.weixin.qq.com/cgi-bin/announce?action=getannouncement&announce_id=11531387046zmIME&version=&lang=zh_CN`,是无法直接使用了,好奇下这是个 bug 还是说设计如此(feature)?(还没来得及看这部分的处理逻辑
This commit is contained in:
凉凉 2018-10-15 16:26:27 +08:00 committed by DIYgod
parent a7437206e2
commit 9dd63f19ff
3 changed files with 37 additions and 0 deletions

View File

@ -937,6 +937,10 @@ GitHub 官方也提供了一些 RSS:
<route name="应用更新" author="DIYgod" example="/xclient/app/sketch" path="/xclient/app/:name" :paramsDesc="['应用名, 可在应用页 URL 中找到']"/>
### 微信公众平台
<route name="系统公告栏目" author="xyqfer" example="/wechat/announce" path="/wechat/announce" />
## 大学通知
### 上海海事大学

View File

@ -451,6 +451,7 @@ router.get('/hopper/:lowestOnly/:from/:to?', require('./routes/hopper/index'));
// wechat
router.get('/wechat/wasi/:id', require('./routes/wechat/wasi'));
router.get('/wechat/announce', require('./routes/wechat/announce'));
// 马蜂窝
router.get('/mafengwo/note/:type', require('./routes/mafengwo/note'));

32
routes/wechat/announce.js Normal file
View File

@ -0,0 +1,32 @@
const axios = require('../../utils/axios');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const { data: htmlString } = await axios({
method: 'get',
url: 'https://mp.weixin.qq.com/cgi-bin/announce?action=getannouncementlist&lang=zh_CN',
});
const $ = cheerio.load(htmlString);
const announceList = [];
$('.mp_news_list > .mp_news_item').each(function() {
const $item = $(this);
const $link = $item.find('a');
const time = $item.find('.read_more').text();
const title = $item.find('strong').text();
announceList.push({
title: `${time} ${title}`,
link: `https://mp.weixin.qq.com${$link.attr('href')}`,
description: title,
pubDate: new Date(time).toUTCString(),
});
});
ctx.state.data = {
title: '微信公众平台-系统公告栏目',
link: 'https://mp.weixin.qq.com/cgi-bin/announce?action=getannouncementlist&lang=zh_CN&token=',
item: announceList,
};
};