Files
RSSHub/lib/v2/hit/jwc.js
T
7ef81ae8d8 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>
2022-09-12 03:30:11 +08:00

61 lines
2.1 KiB
JavaScript

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,
};
};