feat: add 东莞教研网 (#4879)

This commit is contained in:
Ethan Shen 2020-06-01 12:05:23 +08:00 committed by GitHub
parent 26cd2cb2c8
commit 561e8ba4a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 82 additions and 0 deletions

View File

@ -235,6 +235,18 @@ type 为 all 时category 参数不支持 cost 和 free
<Route author="LogicJake" example="/kpmg/insights" path="/kpmg/insights" />
## 东莞教研网
### 信息公开
<Route author="nczitzk" example="/dgjyw/news" path="/dgjyw/:type" :paramsDesc="['分类']">
| 动态 | 公示 | 通知 |
| ---- | ------------ | ------ |
| news | announcement | notice |
</Route>
## 福利资源 - met.red
### 福利资源 - met.red

View File

@ -2795,4 +2795,7 @@ router.get('/law/jh', require('./routes/law/jh'));
// Mobilism
router.get('/mobilism/release', require('./routes/mobilism/release'));
// 东莞教研网
router.get('/dgjyw/:type', require('./routes/dgjyw/index'));
module.exports = router;

67
lib/routes/dgjyw/index.js Normal file
View File

@ -0,0 +1,67 @@
const url = require('url');
const got = require('@/utils/got');
const cheerio = require('cheerio');
const rootUrl = 'http://zxls.dgjyw.com/';
const config = {
news: {
link: '/node/57620',
title: '动态',
},
announcement: {
link: '/node/57725',
title: '公示',
},
notice: {
link: '/node/57621',
title: '通知',
},
};
module.exports = async (ctx) => {
const cfg = config[ctx.params.type];
if (!cfg) {
throw Error('Bad category. See <a href="https://docs.rsshub.app/other.html#dong-guan-jiao-yan-wang">docs</a>');
}
const currentUrl = url.resolve(rootUrl, cfg.link);
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
const list = $('ul.list-ul')
.eq(2)
.find('li')
.slice(0, 20)
.map((_, item) => {
item = $(item);
const a = item.find('a[title]');
return {
title: a.text(),
link: a.attr('href'),
pubDate: new Date(new Date().getFullYear().toString().substr(0, 2) + item.find('span').text()).toUTCString(),
};
})
.get();
const items = await Promise.all(
list.map(
async (item) =>
await ctx.cache.tryGet(item.link, async () => {
const res = await got({ method: 'get', url: item.link });
const content = cheerio.load(res.data);
item.description = content('div.text').html();
return item;
})
)
);
ctx.state.data = {
title: '东莞教研网 - ' + cfg.title,
link: rootUrl,
item: items,
};
};