diff --git a/docs/university.md b/docs/university.md index f87f9f7b76..df701862dc 100644 --- a/docs/university.md +++ b/docs/university.md @@ -186,6 +186,16 @@ pageClass: routes +## 北京物资学院 + +### 通知公告 + + + +::: warning 注意 +由于学校官网对非大陆 IP 的访问存在限制,需自行部署。 +::: + ## 北京邮电大学 ### 硕士研究生招生通知 diff --git a/lib/router.js b/lib/router.js index 92353cd1a6..d7d9de151e 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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')); // 新榜 diff --git a/lib/routes/universities/bwu/news.js b/lib/routes/universities/bwu/news.js new file mode 100644 index 0000000000..d2b60c55ec --- /dev/null +++ b/lib/routes/universities/bwu/news.js @@ -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, + }; +}; diff --git a/lib/routes/universities/bwu/utils.js b/lib/routes/universities/bwu/utils.js new file mode 100644 index 0000000000..ea671919a7 --- /dev/null +++ b/lib/routes/universities/bwu/utils.js @@ -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, +};