feat(route): add 哈尔滨工业大学研究生院通知公告 (#10747)

* 添加"哈尔滨工业大学研究生院通知公告"路由

* 修改路由为v2 script

* chore(deps): bump puppeteer from 17.1.2 to 17.1.3 (#1094)

Bumps [puppeteer](https://github.com/puppeteer/puppeteer) from 17.1.2 to 17.1.3.
- [Release notes](https://github.com/puppeteer/puppeteer/releases)
- [Changelog](https://github.com/puppeteer/puppeteer/blob/main/CHANGELOG.md)
- [Commits](https://github.com/puppeteer/puppeteer/compare/v17.1.2...v17.1.3)

---
updated-dependencies:
- dependency-name: puppeteer
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Update lib/v2/hit/hitgs.js

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* change code style of hitgs.js

* add radar.js

* change http to https for older HIT files

* refactor: migrate to v2

* docs: fix format

* fix: code scan

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This commit is contained in:
Honglin Mu 2022-09-12 03:30:11 +08:00 committed by GitHub
parent b8e567b9e4
commit 7ef81ae8d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 222 additions and 145 deletions

View File

@ -1233,23 +1233,33 @@ category 列表:
## 哈尔滨工业大学
### 哈尔滨工业大学教务处通知公告
::: warning 注意
哈工大网站疑似禁止了`rsshub.app`的访问,使用路由需要自行 [部署](https://docs.rsshub.app/install)。
:::
<Route author="lty96117" example="/hit/jwc" path="/hit/jwc"/>
### 教务处通知公告
<Route author="lty96117" example="/hit/jwc" path="/hit/jwc" radar="1" rssbud="1"/>
### 今日哈工大
<Route author="ranpox" example="/hit/today/10" path="/hit/today/:category" :paramsDesc="['分类编号,`10`为公告公示,`11`为新闻快讯,同时支持详细分类,使用方法见下']"/>
<Route author="ranpox" example="/hit/today/10" path="/hit/today/:category" :paramsDesc="['分类编号,`10`为公告公示,`11`为新闻快讯,同时支持详细分类,使用方法见下']" radar="1" rssbud="1">
::: tip 提示
今日哈工大的文章分为公告公示和新闻快讯,每个页面右侧列出了更详细的分类,其编号为每个 URL 路径的最后一个数字。
例如会议讲座的路径为`/taxonomy/term/10/25`,则可以通过`/hit/today/25`订阅该详细类别。
例如会议讲座的路径为`/taxonomy/term/10/25`,则可以通过 [`/hit/today/25`](https://rsshub.app/hit/today/25) 订阅该详细类别。
:::
::: warning 注意
部分文章需要经过统一身份认证后才能阅读全文。
:::
</Route>
### 研究生院通知公告
<Route author="hlmu" example="/hit/hitgs" path="/hit/hitgs" radar="1" rssbud="1"/>
## 哈尔滨工业大学(深圳)
### 哈尔滨工业大学(深圳) - 新闻中心

View File

@ -527,9 +527,9 @@ router.get('/hhu/libNews', lazyloadRouteHandler('./routes/universities/hhu/libNe
// 河海大学常州校区
router.get('/hhu/libNewsc', lazyloadRouteHandler('./routes/universities/hhu/libNewsc'));
// 哈尔滨工业大学
router.get('/hit/jwc', lazyloadRouteHandler('./routes/universities/hit/jwc'));
router.get('/hit/today/:category', lazyloadRouteHandler('./routes/universities/hit/today'));
// 哈尔滨工业大学 migrated to v2
// router.get('/hit/jwc', lazyloadRouteHandler('./routes/universities/hit/jwc'));
// router.get('/hit/today/:category', lazyloadRouteHandler('./routes/universities/hit/today'));
// 哈尔滨工业大学(深圳)
router.get('/hitsz/article/:category?', lazyloadRouteHandler('./routes/universities/hitsz/article'));

View File

@ -1,53 +0,0 @@
const got = require('../../../utils/got');
const cheerio = require('cheerio');
const url = require('url');
const baseUrl = 'http://jwc.hit.edu.cn';
const type = (filename) => filename.split('.').pop();
module.exports = async (ctx) => {
const response = await got.get(`${baseUrl}/2591/list.htm`);
const { data } = response;
const $ = cheerio.load(data);
const links = $('.news_list li')
.slice(0, 10)
.map((i, el) => ({
pubDate: new Date($('span.fbll', el).children().first().text().replace('[', '')).toUTCString(),
link: url.resolve(baseUrl, $('a', el).attr('href')),
title: $('a', el).attr('title'),
}))
.get();
const item = await Promise.all(
[...links].slice(0, 10).map(async ({ pubDate, link, title }) => {
if (type(link) === 'htm') {
const { data } = await got.get(link);
const $ = cheerio.load(data);
const author = $('p.arti_metas>span:nth-child(3)').text().trim();
const description =
$('div.wp_articlecontent').html() &&
$('div.wp_articlecontent')
.html()
.replace(/src="\//g, `src="${url.resolve(baseUrl, '.')}`)
.replace(/href="\//g, `href="${url.resolve(baseUrl, '.')}`)
.trim();
// check for some bug links.
if (!description) {
return;
}
return Promise.resolve({ pubDate, author, link, title, description });
} else {
// file to download
return Promise.resolve({ pubDate, link, title, description: '此链接为文件,点击以下载' });
}
})
);
ctx.state.data = {
title: '哈尔滨工业大学教务处通知公告',
link: `${baseUrl}/2591/list.htm`,
item: item.filter((x) => x),
};
};

View File

@ -1,85 +0,0 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const url = require('url');
module.exports = async (ctx) => {
const host = 'http://today.hit.edu.cn';
const category = ctx.params.category;
const response = await got({
method: 'get',
url: host + '/category/' + category,
headers: {
Referer: host,
},
});
const $ = cheerio.load(response.data);
const category_name = $('div.banner-title').text();
const list = $('.paragraph li')
.slice(0, 10)
.map((i, e) => ({
path: $('span span a', e).attr('href'),
title: $('span span a', e).text(),
author: $('div a', e).attr('hreflang', 'zh-hans').text(),
}))
.get();
const out = await Promise.all(
list.map(async (item) => {
const { path, title, author } = item;
const link = host + path;
const cache = await ctx.cache.get(link);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
const response = await got({
method: 'get',
url: link,
headers: {
Referer: host,
},
});
if (response.req._headers.host === 'ids.hit.edu.cn') {
const single = {
pubDate: new Date(link.split('/').slice(-4, -1).join('-')).toUTCString(),
author,
link,
title,
description: '请进行统一身份认证后查看全文',
};
ctx.cache.set(link, JSON.stringify(single));
return Promise.resolve(single);
}
const $ = cheerio.load(response.data);
const description =
$('.article-content').html() &&
$('.article-content')
.html()
.replace(/src="\//g, `src="${url.resolve(host, '.')}`)
.replace(/href="\//g, `href="${url.resolve(host, '.')}`)
.trim();
const single = {
pubDate: new Date($('.left-attr.first').text()).toUTCString(),
author,
link,
title,
description,
};
ctx.cache.set(link, JSON.stringify(single));
return Promise.resolve(single);
})
);
ctx.state.data = {
title: '今日哈工大-' + category_name,
link: host + 'category/' + category,
description: '今日哈工大-' + category_name,
item: out,
};
};

46
lib/v2/hit/hitgs.js Normal file
View File

@ -0,0 +1,46 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const host = 'https://hitgs.hit.edu.cn';
const response = await got(host + '/tzgg/list.htm', {
headers: {
Referer: host,
},
});
const $ = cheerio.load(response.data);
const list = $('.news_list li')
.map((i, e) => ({
pubDate: parseDate($('span:nth-child(4)', e).text()),
title: $('span.Article_BelongCreateOrg.newsfb', e).text() + $('span a', e).attr('title'),
category: $('span.Article_BelongCreateOrg.newsfb', e).text().slice(1, -1),
link: host + $('span a', e).attr('href'),
}))
.get();
const out = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const response = await got(item.link, {
headers: {
Referer: host,
},
});
const $ = cheerio.load(response.data);
item.description = $('.wp_articlecontent').html();
item.author = $('div.infobox > div > p > span:nth-child(3)').text().slice(3);
return item;
})
)
);
ctx.state.data = {
title: '哈工大研究生院通知公告',
link: host + '/tzgg/list.htm',
description: '哈尔滨工业大学研究生院通知公告',
item: out,
};
};

60
lib/v2/hit/jwc.js Normal file
View File

@ -0,0 +1,60 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const baseUrl = 'https://jwc.hit.edu.cn';
const type = (filename) => filename.split('.').pop();
module.exports = async (ctx) => {
const response = await got(`${baseUrl}/2591/list.htm`);
const { data } = response;
const $ = cheerio.load(data);
const links = $('.news_list li')
.toArray()
.map((el) => {
el = $(el);
return {
pubDate: parseDate(el.find('span.fbll').children().first().text().replace(/\[/g, '')),
link: new URL(el.find('a').attr('href'), baseUrl).href,
title: el.find('a').attr('title'),
};
});
const items = await Promise.all(
links.map((item) =>
ctx.cache.tryGet(item.link, async () => {
if (type(item.link) === 'htm') {
try {
const { data } = await got(item.link);
const $ = cheerio.load(data);
const author = $('p.arti_metas>span:nth-child(3)').text().trim();
const description =
$('div.wp_articlecontent').html() &&
$('div.wp_articlecontent')
.html()
.replace(/src="\//g, `src="${new URL('.', baseUrl).href}`)
.replace(/href="\//g, `href="${new URL('.', baseUrl).href}`)
.trim();
item.author = author;
item.description = description;
} catch (e) {
// intranet
}
} else {
// file to download
item.description = '此链接为文件,点击以下载';
}
return item;
})
)
);
ctx.state.data = {
title: '哈尔滨工业大学教务处通知公告',
link: `${baseUrl}/2591/list.htm`,
item: items,
};
};

5
lib/v2/hit/maintainer.js Normal file
View File

@ -0,0 +1,5 @@
module.exports = {
'/hitgs': ['hlmu'],
'/jwc': ['lty96117'],
'/today/:category': ['ranpox'],
};

29
lib/v2/hit/radar.js Normal file
View File

@ -0,0 +1,29 @@
module.exports = {
'hit.edu.cn': {
_name: '哈尔滨工业大学',
jwc: [
{
title: '哈尔滨工业大学教务处通知公告',
docs: 'https://docs.rsshub.app/university.html#ha-er-bin-gong-ye-da-xue',
source: '/*',
target: '/hit/jwc',
},
],
today: [
{
title: '今日哈工大',
docs: 'https://docs.rsshub.app/university.html#ha-er-bin-gong-ye-da-xue',
source: '/category/:category',
target: '/hit/today/:category',
},
],
hitgs: [
{
title: '哈工大研究生院通知公告',
docs: 'https://docs.rsshub.app/university.html#ha-er-bin-gong-ye-da-xue',
source: '/*',
target: '/hit/hitgs',
},
],
},
};

6
lib/v2/hit/router.js Normal file
View File

@ -0,0 +1,6 @@
module.exports = function (router) {
// 哈尔滨工业大学
router.get('/hitgs', require('./hitgs'));
router.get('/jwc', require('./jwc'));
router.get('/today/:category', require('./today'));
};

59
lib/v2/hit/today.js Normal file
View File

@ -0,0 +1,59 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');
module.exports = async (ctx) => {
const host = 'https://today.hit.edu.cn';
const category = ctx.params.category;
const response = await got(host + '/category/' + category, {
headers: {
Referer: host,
},
});
const $ = cheerio.load(response.data);
const list = $('.paragraph li')
.toArray()
.map((e) => ({
link: new URL($('span span a', e).attr('href'), host).href,
title: $('span span a', e).text(),
author: $('div a', e).attr('hreflang', 'zh-hans').text(),
pubDate: timezone(parseDate($('span span a', e).attr('href').split('/').slice(-4, -1).join(), 'YYYYMMDD'), 8),
}));
const out = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
try {
const response = await got(item.link, {
headers: {
Referer: host,
},
});
const $ = cheerio.load(response.data);
item.pubDate = timezone(parseDate($('.left-attr.first').text().trim()), 8);
item.description =
$('.article-content').html() &&
$('.article-content')
.html()
.replace(/src="\//g, `src="${new URL('.', host).href}`)
.replace(/href="\//g, `href="${new URL('.', host).href}`)
.trim();
} catch (e) {
// intranet
item.description = '请进行统一身份认证后查看全文';
}
return item;
})
)
);
ctx.state.data = {
title: $('head title').text().trim(),
link: host + '/category/' + category,
item: out,
};
};