diff --git a/lib/router.js b/lib/router.js index ca0d3a585..1a6dfbbdc 100644 --- a/lib/router.js +++ b/lib/router.js @@ -569,9 +569,9 @@ router.get('/thu/:type', lazyloadRouteHandler('./routes/universities/thu/index') // router.get('/pku/bbs/hot', lazyloadRouteHandler('./routes/universities/pku/bbs/hot')); // router.get('/pku/scc/recruit/:type?', lazyloadRouteHandler('./routes/universities/pku/scc/recruit')); -// 上海海事大学 -router.get('/shmtu/www/:type', lazyloadRouteHandler('./routes/universities/shmtu/www')); -router.get('/shmtu/jwc/:type', lazyloadRouteHandler('./routes/universities/shmtu/jwc')); +// 上海海事大学 migrated to v2 +// router.get('/shmtu/www/:type', lazyloadRouteHandler('./routes/universities/shmtu/www')); +// router.get('/shmtu/jwc/:type', lazyloadRouteHandler('./routes/universities/shmtu/jwc')); // 上海海洋大学 router.get('/shou/www/:type', lazyloadRouteHandler('./routes/universities/shou/www')); diff --git a/lib/routes/universities/shmtu/jwc.js b/lib/routes/universities/shmtu/jwc.js deleted file mode 100644 index 3ff4e8667..000000000 --- a/lib/routes/universities/shmtu/jwc.js +++ /dev/null @@ -1,75 +0,0 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const url = require('url'); -const host = 'https://jwc.shmtu.edu.cn'; - -async function load(link) { - const response = await got.get(link); - const $ = cheerio.load(response.data); - - $('.field-item img').each((index, elem) => { - const $elem = $(elem); - const src = $elem.attr('src'); - if (src) { - $elem.attr('src', url.resolve(host, src)); - } - $elem.removeAttr('style'); - $elem.removeAttr('alt'); - }); - - const description = $('.field-item').html(); - - return { description }; -} - -const ProcessFeed = (list, caches) => - Promise.all( - list.map(async (item) => { - const $ = cheerio.load(item); - - const itemUrl = url.resolve(host, $('.views-field-nothing', item).find('a').attr('href')); - const category = $('.views-field-field-xxlb', item).text().trim(); - const author = $('.views-field-field-xxly', item).text().trim(); - - const single = { - title: $('.views-field-nothing', item).text().trim(), - link: itemUrl, - guid: itemUrl, - pubDate: new Date($('.views-field-created', item).text()).toUTCString(), - category, - author: author === '' ? category : author, - }; - - const other = await caches.tryGet(itemUrl, () => load(itemUrl)); - - return Promise.resolve(Object.assign({}, single, other)); - }) - ); - -module.exports = async (ctx) => { - const type = ctx.params.type; - const limit = ctx.query.limit || 4; - const info = type === 'jwgg' ? '教务公告' : '教务新闻'; - - const response = await got({ - method: 'get', - url: host + `/${type}/list.htm`, - headers: { - Referer: host, - }, - }); - - const $ = cheerio.load(response.data); - const list = $('tr', 'tbody') - .slice(0, limit > 15 ? 15 : limit) - .get(); - - const result = await ProcessFeed(list, ctx.cache); - - ctx.state.data = { - title: `上海海事大学 ${info}`, - link: host + `/${type}`, - description: '上海海事大学 教务信息', - item: result, - }; -}; diff --git a/lib/routes/universities/shmtu/www.js b/lib/routes/universities/shmtu/www.js deleted file mode 100644 index 717a50d8d..000000000 --- a/lib/routes/universities/shmtu/www.js +++ /dev/null @@ -1,61 +0,0 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const url = require('url'); -const host = 'http://www.shmtu.edu.cn'; - -async function load(link) { - const response = await got.get(link); - const $ = cheerio.load(response.data); - - const description = $('meta[name="description"]').attr('content'); - - return { description }; -} - -const ProcessFeed = (list, caches) => - Promise.all( - list.map(async (item) => { - const $ = cheerio.load(item); - - const itemUrl = url.resolve(host, $('.title', item).find('a').attr('href')); - const category = $('.department', item).text().trim(); - - const single = { - title: $('.title', item).text().trim(), - link: itemUrl, - guid: itemUrl, - pubDate: new Date($('.date', item).find('span').find('span').attr('content')).toUTCString(), - category, - author: category, - }; - - const other = await caches.tryGet(itemUrl, () => load(itemUrl)); - - return Promise.resolve(Object.assign({}, single, other)); - }) - ); - -module.exports = async (ctx) => { - const type = ctx.params.type; - const info = type === 'notes' ? '通知公告' : '学术讲座'; - - const response = await got({ - method: 'get', - url: host + `/${type}`, - headers: { - Referer: host, - }, - }); - - const $ = cheerio.load(response.data); - const list = $('tr', 'tbody').slice(0, 10).get(); - - const result = await ProcessFeed(list, ctx.cache); - - ctx.state.data = { - title: `上海海事大学 ${info}`, - link: host + `/${type}`, - description: '上海海事大学 官网信息', - item: result, - }; -}; diff --git a/lib/v2/shmtu/jwc.js b/lib/v2/shmtu/jwc.js new file mode 100644 index 000000000..f49f43db0 --- /dev/null +++ b/lib/v2/shmtu/jwc.js @@ -0,0 +1,57 @@ +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, + }; +}; diff --git a/lib/v2/shmtu/maintainer.js b/lib/v2/shmtu/maintainer.js new file mode 100644 index 000000000..10d6dff98 --- /dev/null +++ b/lib/v2/shmtu/maintainer.js @@ -0,0 +1,4 @@ +module.exports = { + '/jwc/:type': ['simonsmh'], + '/www/:type': ['simonsmh'], +}; diff --git a/lib/v2/shmtu/radar.js b/lib/v2/shmtu/radar.js new file mode 100644 index 000000000..9278c6381 --- /dev/null +++ b/lib/v2/shmtu/radar.js @@ -0,0 +1,21 @@ +module.exports = { + 'shmtu.edu.cn': { + _name: '上海海事大学', + jwc: [ + { + title: '教务信息', + docs: 'https://docs.rsshub.app/university.html#shang-hai-dian-li-da-xue', + source: ['/:type'], + target: '/shmtu/jwc/:type', + }, + ], + www: [ + { + title: '官网信息', + docs: 'https://docs.rsshub.app/university.html#shang-hai-dian-li-da-xue', + source: ['/:type'], + target: '/shmtu/www/:type', + }, + ], + }, +}; diff --git a/lib/v2/shmtu/router.js b/lib/v2/shmtu/router.js new file mode 100644 index 000000000..f8300621c --- /dev/null +++ b/lib/v2/shmtu/router.js @@ -0,0 +1,4 @@ +module.exports = (router) => { + router.get('/jwc/:type', require('./jwc')); + router.get('/www/:type', require('./www')); +}; diff --git a/lib/v2/shmtu/www.js b/lib/v2/shmtu/www.js new file mode 100644 index 000000000..6040dea87 --- /dev/null +++ b/lib/v2/shmtu/www.js @@ -0,0 +1,58 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const host = 'https://www.shmtu.edu.cn'; + +async function load(link) { + const response = await got.get(link, { https: { rejectUnauthorized: false } }); + const $ = cheerio.load(response.data); + + return $('article').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 === 'notes' ? '通知公告' : '学术讲座'; + + const response = await got(`${host}/${type}`, { + headers: { + Referer: host, + }, + https: { rejectUnauthorized: false }, + }); + + const $ = cheerio.load(response.data); + const list = $('tbody tr') + .toArray() + .map((item) => { + item = $(item); + const category = item.find('.department').text().trim(); + return { + title: item.find('.title a').text().trim(), + link: new URL(item.find('a').attr('href'), host).href, + pubDate: parseDate(item.find('.date-display-single').attr('content')), + category, + author: category, + }; + }); + + const result = await ProcessFeed(list, ctx.cache); + + ctx.state.data = { + title: `上海海事大学 ${info}`, + link: `${host}/${type}`, + description: '上海海事大学 官网信息', + item: result, + }; +};