Files
RSSHub/lib/v2/shmtu/jwc.js
T
imbytecat 3706b428b8 fix: ignore shmtu ssl verification & migrate to route v2 (#11403)
* ignore shmtu ssl verification

* migrate route v1 to v2

* fix: add missing radar and maintainer
2022-12-08 03:11:18 +08:00

58 lines
1.7 KiB
JavaScript

const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');
const host = 'https://jwc.shmtu.edu.cn';
async function load(link) {
const response = await got(link, { https: { rejectUnauthorized: false } });
const $ = cheerio.load(response.data);
return $('.wp_articlecontent').html();
}
const ProcessFeed = (list, caches) =>
Promise.all(
list.map((item) =>
caches.tryGet(item.link, async () => {
item.description = await load(item.link);
return item;
})
)
);
module.exports = async (ctx) => {
const type = ctx.params.type;
const info = type === 'jwgg' ? '教务公告' : '教务新闻';
const response = await got(`${host}/${type}/list.htm`, {
headers: {
Referer: host,
},
https: { rejectUnauthorized: false },
});
const $ = cheerio.load(response.data);
const list = $('tbody tr')
.toArray()
.map((item) => {
item = $(item);
return {
title: item.find('.views-field-nothing a').attr('title').trim(),
link: new URL(item.find('a').attr('href'), host).href,
pubDate: timezone(parseDate(item.find('.pubdate').text()), 8),
category: item.find('.views-field-field-xxlb').text(),
author: item.find('.views-field-field-xxly').text(),
};
});
const result = await ProcessFeed(list, ctx.cache);
ctx.state.data = {
title: `上海海事大学 ${info}`,
link: `${host}/${type}`,
description: '上海海事大学 教务信息',
item: result,
};
};