feat(route): add ielts (#9217)

* feat: add ielts

* feat: ielts suggestion
This commit is contained in:
zenxds
2022-03-01 10:23:44 +08:00
committed by GitHub
parent cdcb2e580b
commit 18d0a7f6cd
5 changed files with 83 additions and 0 deletions

View File

@@ -81,6 +81,12 @@ path="/ctfhub/upcoming/:limit?"
<Route author="liecn" example="/gradcafe/result/computer" path="/gradcafe/result/:type" :paramsDesc="['按关键词进行搜索,如 computer']"/>
## IELTS 雅思
### 最新消息
<Route author="zenxds" example="/ielts" path="/ielts"/>
## MarginNote
### 标签

58
lib/v2/ielts/index.js Normal file
View File

@@ -0,0 +1,58 @@
const cheerio = require('cheerio');
const got = require('@/utils/got');
const timezone = require('@/utils/timezone');
const { parseDate } = require('@/utils/parse-date');
const targetUrl = 'https://ielts.neea.cn/allnews?locale=zh_CN';
module.exports = async (ctx) => {
const browser = await require('@/utils/puppeteer')();
const page = await browser.newPage();
await page.evaluateOnNewDocument(() => {
const proto = navigator.__proto__;
delete proto.webdriver;
});
await page.goto(targetUrl, {
waitUntil: 'networkidle0',
});
const list = await page.evaluate(() =>
window
.$('#newsListUl li')
.get()
.map((elem) => {
const $elem = window.$(elem);
return {
title: $elem.find('a').text(),
link: $elem.find('a').attr('href'),
pubDate: $elem.find('span').eq(-1).text().replace(/[[\]]/g, '').trim(),
};
})
);
browser.close();
list.sort((a, b) => parseDate(b.pubDate) - parseDate(a.pubDate));
list.forEach((item) => {
item.pubDate = timezone(parseDate(item.pubDate), +8);
});
const items = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const $ = cheerio.load(detailResponse.data);
item.description = $('.content').html();
return item;
})
)
);
ctx.state.data = {
title: 'IELTS雅思最新消息',
link: targetUrl,
item: items,
};
};

View File

@@ -0,0 +1,3 @@
module.exports = {
'/': ['zenxds'],
};

13
lib/v2/ielts/radar.js Normal file
View File

@@ -0,0 +1,13 @@
module.exports = {
'neea.cn': {
_name: 'IELTS雅思',
ielts: [
{
title: '最新消息',
docs: 'https://docs.rsshub.app/study.html#ielts-ya-si',
source: ['/allnews'],
target: '/ielts',
},
],
},
};

3
lib/v2/ielts/router.js Normal file
View File

@@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/', require('./index'));
};