fix: 优化四川大学通知 (#3095)

This commit is contained in:
Steve Lee 2019-09-17 17:20:12 +08:00 committed by DIYgod
parent 48595a0b72
commit b2735ec978
2 changed files with 27 additions and 6 deletions

View File

@ -16,9 +16,15 @@ async function load_detail(list, cache) {
},
});
const detail = cheerio.load(detail_response.data);
const date_part = detail('.list-main-content > .list-a-content > .page-date > span')
.text()
.slice(6, 16)
.split('-');
const date = new Date(date_part[0], date_part[1] - 1, date_part[2]);
return {
title: notice_item('li').attr('title'),
description: detail('.list-main-content > .list-a-content > .page-content').html(),
pubDate: date,
link: url,
};
});
@ -36,9 +42,7 @@ module.exports = async (ctx) => {
},
});
const $ = cheerio.load(response.data);
const list = $('.list-ll-b > .edit_option >.list-llb-box > .list-llb-s > .list-llb-list')
.slice(0, 10)
.get();
const list = $('.list-ll-b > .edit_option >.list-llb-box > .list-llb-s > .list-llb-list').get();
const detail = await load_detail(list, ctx.cache);
ctx.state.data = {
title: '四川大学教务处 - 通知公告',

View File

@ -6,6 +6,11 @@ async function load_detail(list, cache) {
list.map(async (item) => {
const notice_item = cheerio.load(item);
const url = 'http://xsc.scu.edu.cn' + notice_item('a').attr('href');
const date_part = notice_item('a > span')
.text()
.split('-');
const date = new Date(new Date().getFullYear(), date_part[0] - 1, date_part[1]);
return await cache.tryGet(url, async () => {
const detail_response = await got({
method: 'get',
@ -19,6 +24,7 @@ async function load_detail(list, cache) {
return {
title: notice_item('a').attr('title'),
description: detail('.news-content').html(),
pubDate: date,
link: url,
};
});
@ -27,7 +33,7 @@ async function load_detail(list, cache) {
}
module.exports = async (ctx) => {
const response = await got({
const index_response = await got({
method: 'get',
url: 'http://xsc.scu.edu.cn/WEBSITE/XG',
headers: {
@ -35,10 +41,21 @@ module.exports = async (ctx) => {
},
});
const data = response.data;
const index_data = index_response.data;
const $_ = cheerio.load(index_data);
const notice_url = 'http://xsc.scu.edu.cn' + $_('.news-pannel.notice-news > .news-head > a').attr('href');
const response = await got({
method: 'get',
url: notice_url,
headers: {
Host: 'xsc.scu.edu.cn',
},
});
const data = response.data;
const $ = cheerio.load(data);
const list = $('.news-pannel.notice-news > .news-body > .news-list > ul > li').get();
const list = $('.news-list > ul > li').get();
const detail = await load_detail(list, ctx.cache);