feat: add 北京物资学院通知公告 (#5196)

This commit is contained in:
Mason 2020-07-29 01:22:37 +08:00 committed by GitHub
parent dc818428f2
commit d7fca5bf03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 94 additions and 0 deletions

View File

@ -186,6 +186,16 @@ pageClass: routes
</Route>
## 北京物资学院
### 通知公告
<Route author="Muxq99" example="/bwu/news" path="/bwu/news" />
::: warning 注意
由于学校官网对非大陆 IP 的访问存在限制,需自行部署。
:::
## 北京邮电大学
### 硕士研究生招生通知

View File

@ -2971,6 +2971,8 @@ router.get('/ngbj/cat/:cat', require('./routes/niaogebiji/cat'));
// 东方我乐多丛志
router.get('/touhougarakuta/:language/:type', require('./routes/touhougarakuta'));
// 北京物资学院
router.get('/bwu/news', require('./routes/universities/bwu/news'));
// Picuki
router.get('/picuki/profile/:id', require('./routes/picuki/profile'));
// 新榜

View File

@ -0,0 +1,29 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const util = require('./utils');
module.exports = async (ctx) => {
const title = '通知公告';
const host = 'http://news.bwu.edu.cn/';
const path = 'tzgg.htm';
const response = await got({
method: 'get',
url: host + path,
headers: {
Referer: host,
},
});
const $ = cheerio.load(response.data);
const list = $('li[class=show]').slice(0, 25).get();
const result = await util.ProcessFeed(list, ctx.cache);
ctx.state.data = {
title: title + ' - 物院新闻',
link: host + path,
description: title + ' - 北京物资学院新闻中心',
item: result,
};
};

View File

@ -0,0 +1,53 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const url = require('url');
// 处理文章全文
async function load(link) {
const responce = await got.get(link);
const $ = cheerio.load(responce.data);
// 解析日期
const date = new Date(
$('h6[style]')
.text()
.replace('年', '-')
.replace('月', '-')
.replace('日', '')
.match(/\d{4}-\d{2}-\d{2} \d{2}:\d{2}/)
);
const timeZone = 8;
const serverOffset = date.getTimezoneOffset() / 60;
const pubDate = new Date(date.getTime() - 60 * 60 * 1000 * (timeZone + serverOffset)).toUTCString();
// 提取正文
const description = $('div[id^=vsb_content_]').html();
return { description, pubDate };
}
const ProcessFeed = async (list, cache) => {
const host = 'http://news.bwu.edu.cn/';
return await Promise.all(
list.map(async (item) => {
const $ = cheerio.load(item);
const $title = $('span[class=showTitle] a');
const source = $('span[class=showSource] a').text();
const link = url.resolve(host, $title.attr('href'));
const single = {
title: $title.attr('title'),
link: link,
author: source,
guid: link,
};
// 尝试使用缓存
const other = await cache.tryGet(link, async () => await load(link));
// 返回文章信息
return Promise.resolve(Object.assign({}, single, other));
})
);
};
module.exports = {
ProcessFeed,
};