mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-07 21:47:57 +08:00
feat: add重庆大学新闻网-学术预告 (#2617)
This commit is contained in:
@@ -923,6 +923,10 @@ https://rsshub.app/**nuist**/`bulletin` 或 https://rsshub.app/**nuist**/`bullet
|
||||
|
||||
<Route author="El-Chiang" example="/cqu/jwc/announcement" path="/universities/cqu/jwc/announcement"/>
|
||||
|
||||
### 新闻网讲座预告
|
||||
|
||||
<Route author="nicolaszf" example="/cqu/news/jzyg" path="/universities/cqu/news/jzyg"/>
|
||||
|
||||
## 重庆科技学院
|
||||
|
||||
### 教务处公告
|
||||
|
||||
@@ -590,6 +590,7 @@ router.get('/heu/ugs/news/:author?/:category?', require('./routes/universities/h
|
||||
|
||||
// 重庆大学
|
||||
router.get('/cqu/jwc/announcement', require('./routes/universities/cqu/jwc/announcement'));
|
||||
router.get('/cqu/news/jzyg', require('./routes/universities/cqu/news/jzyg'));
|
||||
|
||||
// 南京信息工程大学
|
||||
router.get('/nuist/bulletin/:category?', require('./routes/universities/nuist/bulletin'));
|
||||
|
||||
23
lib/routes/universities/cqu/news/jzyg.js
Normal file
23
lib/routes/universities/cqu/news/jzyg.js
Normal file
@@ -0,0 +1,23 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const util = require('./utils');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: 'http://news.cqu.edu.cn/newsv2/info-24.html',
|
||||
});
|
||||
|
||||
const data = response.data;
|
||||
const $ = cheerio.load(data);
|
||||
const list = $('.item').get();
|
||||
|
||||
const result = await util.ProcessFeed(list, ctx.cache);
|
||||
|
||||
ctx.state.data = {
|
||||
title: '重庆大学新闻网-讲座预告',
|
||||
link: 'http://news.cqu.edu.cn/newsv2/info-24.html',
|
||||
description: '重庆大学新闻网-讲座预告',
|
||||
item: result,
|
||||
};
|
||||
};
|
||||
48
lib/routes/universities/cqu/news/utils.js
Normal file
48
lib/routes/universities/cqu/news/utils.js
Normal file
@@ -0,0 +1,48 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
// 加载文章页
|
||||
async function load(link) {
|
||||
const response = await got.get(link);
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
// 提取内容
|
||||
const description = $('.dinfo').html() + $('.acontent').html();
|
||||
|
||||
return { description };
|
||||
}
|
||||
|
||||
const ProcessFeed = async (list, caches) =>
|
||||
await Promise.all(
|
||||
list.map(async (item) => {
|
||||
const $ = cheerio.load(item);
|
||||
|
||||
const $title1 = $('.title a').eq(0);
|
||||
const $title2 = $('.title a').eq(1);
|
||||
let itemUrl = $title2.attr('href');
|
||||
let title = $title1.text() + ' - ' + $title2.text();
|
||||
|
||||
if (typeof itemUrl === 'undefined') {
|
||||
itemUrl = $title1.attr('href');
|
||||
title = $title1.text();
|
||||
}
|
||||
|
||||
// 列表上提取到的信息
|
||||
const single = {
|
||||
title: title,
|
||||
link: itemUrl,
|
||||
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