Skip to content

Commit

Permalink
feat: add 南京理工大学电光学院; fix: 南京理工大学研究生院 (DIYgod#4298)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasongzy authored Apr 2, 2020
1 parent 23720b7 commit 12162d1
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 21 deletions.
18 changes: 18 additions & 0 deletions docs/university.md
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,24 @@ category 列表:

</Route>

### 南京理工大学电光学院

<Route author="jasongzy" example="/njust/eo/17/tz" path="/njust/eo/:grade?/:type?" :paramsDesc="['年级默认为 `17`', '类别默认为 `tz`']">

grade 列表:

| 本科 2016 级 | 本科 2017 级 | 本科 2018 级 | 本科 2019 级 |
| ------------ | ------------ | ------------ | ------------ |
| 16 | 17 | 18 | 19 |

type 列表:

| 年级通知(通知公告) | 每日动态(主任寄语) |
| -------------------- | -------------------- |
| tz | dt |

</Route>

## 南京林业大学

### 教务处
Expand Down
1 change: 1 addition & 0 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,7 @@ router.get('/cczu/news/:category?', require('./routes/universities/cczu/news'));
router.get('/njust/jwc/:type', require('./routes/universities/njust/jwc'));
router.get('/njust/cwc/:type', require('./routes/universities/njust/cwc'));
router.get('/njust/gs/:type', require('./routes/universities/njust/gs'));
router.get('/njust/eo/:grade?/:type?', require('./routes/universities/njust/eo'));

// 四川旅游学院
router.get('/sctu/xgxy', require('./routes/universities/sctu/information-engineer-faculty/index'));
Expand Down
50 changes: 50 additions & 0 deletions lib/routes/universities/njust/eo/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const date = require('@/utils/date');
const cheerio = require('cheerio');
const { getContent } = require('@/routes/universities/njust/eo/util');

const map = new Map([
['16tz', { title: '南京理工大学电光16 -- 通知公告', id: '/_t217/tzgg/list.htm' }],
['16dt', { title: '南京理工大学电光16 -- 主任寄语', id: '/_t217/zrjy/list.htm' }],
['17tz', { title: '南京理工大学电光17 -- 年级通知', id: '/_t689/njtz/list.htm' }],
['17dt', { title: '南京理工大学电光17 -- 每日动态', id: '/_t689/mrdt/list.htm' }],
['18tz', { title: '南京理工大学电光18 -- 年级通知', id: '/_t900/njtz_10234/list.htm' }],
['18dt', { title: '南京理工大学电光18 -- 主任寄语', id: '/_t900/zrjy_10251/list.htm' }],
['19tz', { title: '南京理工大学电光19 -- 通知公告', id: '/_t1163/tzgg_11606/list.htm' }],
['19dt', { title: '南京理工大学电光19 -- 每日动态', id: '/_t1163/mrdt_11608/list.htm' }],
]);

const baseUrl = 'http://dgxg.njust.edu.cn';

module.exports = async (ctx) => {
const grade = ctx.params.grade || '17';
const type = ctx.params.type || 'tz';
const category = grade + type;
const id = map.get(category).id;

const html = await getContent(baseUrl + id);
const $ = cheerio.load(html);
const list = $('li.list_item');

ctx.state.data = {
title: map.get(category).title,
link: baseUrl + '/' + id.split('/')[1] + '/main.htm',
item:
list &&
list
.map((index, item) => ({
title: $(item)
.find('a')
.text()
.trim(),
pubDate: date(
$(item)
.find('span.Article_PublishDate')
.text()
),
link: $(item)
.find('a')
.attr('href'),
}))
.get(),
};
};
28 changes: 28 additions & 0 deletions lib/routes/universities/njust/eo/util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const delay = (timeout = 1000) => new Promise((resolve) => setTimeout(resolve, timeout));

async function getContent(url) {
const browser = await require('@/utils/puppeteer')();
try {
const page = await browser.newPage();
page.waitForNavigation({
timeout: 20000,
});
// 更改 window.navigator.webdriver 值以避开反爬
await page.evaluateOnNewDocument(() => {
// eslint-disable-next-line no-undef
Object.defineProperty(navigator, 'webdriver', {
get: () => undefined,
});
});
await page.goto(url);
await delay(1000);
const content = await page.content();
return content;
} finally {
browser.close();
}
}

module.exports = {
getContent,
};
44 changes: 23 additions & 21 deletions lib/routes/universities/njust/gs/index.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,42 @@
const got = require('@/utils/got');
const date = require('@/utils/date');
const cheerio = require('cheerio');
const { getContent } = require('@/routes/universities/njust/eo/util');

const map = new Map([
[1, { title: '南京理工大学研究生院 -- 通知公告', id: '/sytzgg_4568' }],
[2, { title: '南京理工大学研究生院 -- 学术公告', id: '/xshdggl' }],
]);

const baseUrl = 'http://gs.njust.edu.cn';

module.exports = async (ctx) => {
const type = Number.parseInt(ctx.params.type);
const id = map.get(type).id;
const baseUrl = 'http://gs.njust.edu.cn';
const res = await got({
method: 'get',
url: baseUrl + id + '/list.htm',
headers: {
Referer: 'https://gs.njust.edu.cn/',
},
});
const $ = cheerio.load(res.data);
const list = $('.wp_article_list li').slice(0, 10);

const html = await getContent(baseUrl + id + '/list.htm');
const $ = cheerio.load(html);
const list = $('li.list_item');

ctx.state.data = {
title: map.get(type).title,
link: 'https://gs.njust.edu.cn',
link: 'http://gs.njust.edu.cn',
item:
list &&
list
.map((index, item) => {
item = $(item);

return {
title: item.find('a').text(),
link: `${baseUrl + $(item.find('a')).attr('href')}`,
pubDate: new Date(item.find('.Article_PublishDate').text()).toUTCString(),
};
})
.map((index, item) => ({
title: $(item)
.find('a')
.text()
.trim(),
pubDate: date(
$(item)
.find('span.Article_PublishDate')
.text()
),
link: $(item)
.find('a')
.attr('href'),
}))
.get(),
};
};

0 comments on commit 12162d1

Please sign in to comment.