mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-12 08:10:32 +08:00
@@ -1,5 +1,11 @@
|
|||||||
# 大学通知
|
# 大学通知
|
||||||
|
|
||||||
|
## 北京理工大学
|
||||||
|
|
||||||
|
<Route name="教务处通知" author="sinofp" example="/bit/jwc" path="/universities/bit/jwc" />
|
||||||
|
|
||||||
|
<Route name="计院通知" author="sinofp" example="/bit/cs" path="/universities/bit/cs" />
|
||||||
|
|
||||||
## 上海海事大学
|
## 上海海事大学
|
||||||
|
|
||||||
<Route name="官网信息" author="simonsmh" example="/shmtu/www/events" path="/shmtu/www/:type" :paramsDesc="['events 为学术讲座, notes 为通知公告']"/>
|
<Route name="官网信息" author="simonsmh" example="/shmtu/www/events" path="/shmtu/www/:type" :paramsDesc="['events 为学术讲座, notes 为通知公告']"/>
|
||||||
|
|||||||
@@ -577,6 +577,10 @@ router.get('/mmgal', require('./routes/galgame/mmgal'));
|
|||||||
// 终点分享
|
// 终点分享
|
||||||
router.get('/zdfx', require('./routes/galgame/zdfx'));
|
router.get('/zdfx', require('./routes/galgame/zdfx'));
|
||||||
|
|
||||||
|
// 北京理工大学
|
||||||
|
router.get('/bit/jwc', require('./routes/universities/bit/jwc/jwc'));
|
||||||
|
router.get('/bit/cs', require('./routes/universities/bit/cs/cs'));
|
||||||
|
|
||||||
// 大连工业大学
|
// 大连工业大学
|
||||||
router.get('/dpu/jiaowu/news/:type?', require('./routes/universities/dpu/jiaowu/news'));
|
router.get('/dpu/jiaowu/news/:type?', require('./routes/universities/dpu/jiaowu/news'));
|
||||||
router.get('/dpu/wlfw/news/:type?', require('./routes/universities/dpu/wlfw/news'));
|
router.get('/dpu/wlfw/news/:type?', require('./routes/universities/dpu/wlfw/news'));
|
||||||
|
|||||||
25
lib/routes/universities/bit/cs/cs.js
Normal file
25
lib/routes/universities/bit/cs/cs.js
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
const axios = require('../../../../utils/axios');
|
||||||
|
const cheerio = require('cheerio');
|
||||||
|
const util = require('./utils');
|
||||||
|
|
||||||
|
module.exports = async (ctx) => {
|
||||||
|
const response = await axios({
|
||||||
|
method: 'get',
|
||||||
|
url: 'http://cs.bit.edu.cn/tzgg',
|
||||||
|
});
|
||||||
|
|
||||||
|
const $ = cheerio.load(response.data);
|
||||||
|
|
||||||
|
const list = $('.box_list01 li')
|
||||||
|
.slice(0, 10)
|
||||||
|
.get();
|
||||||
|
|
||||||
|
const result = await util.ProcessFeed(list, ctx.cache);
|
||||||
|
|
||||||
|
ctx.state.data = {
|
||||||
|
title: $('title').text(),
|
||||||
|
link: 'http://cs.bit.edu.cn/tzgg',
|
||||||
|
description: $('meta[name="description"]').attr('content'),
|
||||||
|
item: result,
|
||||||
|
};
|
||||||
|
};
|
||||||
82
lib/routes/universities/bit/cs/utils.js
Normal file
82
lib/routes/universities/bit/cs/utils.js
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
const axios = require('../../../../utils/axios');
|
||||||
|
const cheerio = require('cheerio');
|
||||||
|
const url = require('url');
|
||||||
|
|
||||||
|
// 专门定义一个function用于加载文章内容
|
||||||
|
async function load(link) {
|
||||||
|
// 异步请求文章
|
||||||
|
const response = await axios.get(link);
|
||||||
|
// 加载文章内容
|
||||||
|
const $ = cheerio.load(response.data);
|
||||||
|
|
||||||
|
// 提取作者
|
||||||
|
const zuozhe = $('.zuozhe')
|
||||||
|
.children()
|
||||||
|
.next();
|
||||||
|
const author = zuozhe.first().text();
|
||||||
|
|
||||||
|
// 解析日期
|
||||||
|
const date = new Date(
|
||||||
|
zuozhe
|
||||||
|
.next()
|
||||||
|
.next()
|
||||||
|
.first()
|
||||||
|
.text()
|
||||||
|
.replace(/[^\d]/g, '-')
|
||||||
|
.match(/\d{4}-\d{2}-\d{2}/)
|
||||||
|
);
|
||||||
|
const timeZone = 8;
|
||||||
|
const serverOffset = date.getTimezoneOffset() / 60;
|
||||||
|
const pubDate = new Date(date.getTime() - 60 * 60 * 1000 * (timeZone + serverOffset)).toUTCString();
|
||||||
|
|
||||||
|
// 还原图片地址, 去除图片onClick事件
|
||||||
|
$('img').each((index, elem) => {
|
||||||
|
const $elem = $(elem);
|
||||||
|
const src = $elem.attr('src');
|
||||||
|
if (src && src !== '') {
|
||||||
|
$elem.attr('src', `http://cs.bit.edu.cn/tzgg/${src}`);
|
||||||
|
}
|
||||||
|
$elem.removeAttr('onclick');
|
||||||
|
});
|
||||||
|
|
||||||
|
// 提取内容
|
||||||
|
const description = $('.wz_art').html();
|
||||||
|
|
||||||
|
// 返回解析的结果
|
||||||
|
return { author, description, pubDate };
|
||||||
|
}
|
||||||
|
|
||||||
|
const ProcessFeed = async (list, caches) => {
|
||||||
|
const host = 'http://cs.bit.edu.cn/tzgg/';
|
||||||
|
|
||||||
|
// 使用 Promise.all() 进行 async 并发
|
||||||
|
return await Promise.all(
|
||||||
|
// 遍历每一篇文章
|
||||||
|
list.map(async (item) => {
|
||||||
|
const $ = cheerio.load(item);
|
||||||
|
|
||||||
|
const $title = $('a');
|
||||||
|
// 还原相对链接为绝对链接
|
||||||
|
const itemUrl = url.resolve(host, $title.attr('href'));
|
||||||
|
|
||||||
|
// 列表上提取到的信息
|
||||||
|
const single = {
|
||||||
|
title: $title.text(),
|
||||||
|
link: itemUrl,
|
||||||
|
// author: '教务部',
|
||||||
|
guid: itemUrl,
|
||||||
|
};
|
||||||
|
|
||||||
|
// 使用tryGet方法从缓存获取内容。
|
||||||
|
// 当缓存中无法获取到链接内容的时候,则使用load方法加载文章内容。
|
||||||
|
const other = await caches.tryGet(itemUrl, async () => await load(itemUrl));
|
||||||
|
|
||||||
|
// 合并解析后的结果集作为该篇文章最终的输出结果
|
||||||
|
return Promise.resolve(Object.assign({}, single, other));
|
||||||
|
})
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
ProcessFeed,
|
||||||
|
};
|
||||||
25
lib/routes/universities/bit/jwc/jwc.js
Normal file
25
lib/routes/universities/bit/jwc/jwc.js
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
const axios = require('../../../../utils/axios');
|
||||||
|
const cheerio = require('cheerio');
|
||||||
|
const util = require('./utils');
|
||||||
|
|
||||||
|
module.exports = async (ctx) => {
|
||||||
|
const response = await axios({
|
||||||
|
method: 'get',
|
||||||
|
url: 'http://jwc.bit.edu.cn/tzgg',
|
||||||
|
});
|
||||||
|
|
||||||
|
const $ = cheerio.load(response.data);
|
||||||
|
|
||||||
|
const list = $('.crules div')
|
||||||
|
.slice(0, 10)
|
||||||
|
.get();
|
||||||
|
|
||||||
|
const result = await util.ProcessFeed(list, ctx.cache);
|
||||||
|
|
||||||
|
ctx.state.data = {
|
||||||
|
title: $('title').text(),
|
||||||
|
link: 'http://jwc.bit.edu.cn/tzgg',
|
||||||
|
description: '北京理工大学教务部',
|
||||||
|
item: result,
|
||||||
|
};
|
||||||
|
};
|
||||||
72
lib/routes/universities/bit/jwc/utils.js
Normal file
72
lib/routes/universities/bit/jwc/utils.js
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
const axios = require('../../../../utils/axios');
|
||||||
|
const cheerio = require('cheerio');
|
||||||
|
const url = require('url');
|
||||||
|
|
||||||
|
// 专门定义一个function用于加载文章内容
|
||||||
|
async function load(link) {
|
||||||
|
// 异步请求文章
|
||||||
|
const response = await axios.get(link);
|
||||||
|
// 加载文章内容
|
||||||
|
const $ = cheerio.load(response.data);
|
||||||
|
|
||||||
|
// 解析日期
|
||||||
|
const date = new Date(
|
||||||
|
$('.aca_author span')
|
||||||
|
.text()
|
||||||
|
.match(/\d{4}-\d{2}-\d{2}/)
|
||||||
|
);
|
||||||
|
const timeZone = 8;
|
||||||
|
const serverOffset = date.getTimezoneOffset() / 60;
|
||||||
|
const pubDate = new Date(date.getTime() - 60 * 60 * 1000 * (timeZone + serverOffset)).toUTCString();
|
||||||
|
|
||||||
|
// 还原图片地址, 去除图片onClick事件
|
||||||
|
$('img').each((index, elem) => {
|
||||||
|
const $elem = $(elem);
|
||||||
|
const src = $elem.attr('src');
|
||||||
|
if (src && src !== '') {
|
||||||
|
$elem.attr('src', `http://jwc.bit.edu.cn/tzgg/${src}`);
|
||||||
|
}
|
||||||
|
$elem.removeAttr('onclick');
|
||||||
|
});
|
||||||
|
|
||||||
|
// 提取内容
|
||||||
|
const description = $('.aca_article_con').html();
|
||||||
|
|
||||||
|
// 返回解析的结果
|
||||||
|
return { description, pubDate };
|
||||||
|
}
|
||||||
|
|
||||||
|
const ProcessFeed = async (list, caches) => {
|
||||||
|
const host = 'http://jwc.bit.edu.cn/tzgg/';
|
||||||
|
|
||||||
|
// 使用 Promise.all() 进行 async 并发
|
||||||
|
return await Promise.all(
|
||||||
|
// 遍历每一篇文章
|
||||||
|
list.map(async (item) => {
|
||||||
|
const $ = cheerio.load(item);
|
||||||
|
|
||||||
|
const $title = $('a');
|
||||||
|
// 还原相对链接为绝对链接
|
||||||
|
const itemUrl = url.resolve(host, $title.attr('href'));
|
||||||
|
|
||||||
|
// 列表上提取到的信息
|
||||||
|
const single = {
|
||||||
|
title: $title.text(),
|
||||||
|
link: itemUrl,
|
||||||
|
author: '教务部',
|
||||||
|
guid: itemUrl,
|
||||||
|
};
|
||||||
|
|
||||||
|
// 使用tryGet方法从缓存获取内容。
|
||||||
|
// 当缓存中无法获取到链接内容的时候,则使用load方法加载文章内容。
|
||||||
|
const other = await caches.tryGet(itemUrl, async () => await load(itemUrl));
|
||||||
|
|
||||||
|
// 合并解析后的结果集作为该篇文章最终的输出结果
|
||||||
|
return Promise.resolve(Object.assign({}, single, other));
|
||||||
|
})
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
ProcessFeed,
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user