add feed for [sse.tongji.edu.cn] (#984)
This commit is contained in:
parent
16c4361a27
commit
5511b005c6
|
|
@ -1385,6 +1385,18 @@ category 列表:
|
|||
|
||||
</route>
|
||||
|
||||
### 同济大学
|
||||
|
||||
<route name="同济大学软件学院通知" author="sgqy" example="/tju/sse/xwdt" path="/tju/sse/:type?" :paramsDesc="['通知类型. 默认为 `xwdt`']">
|
||||
|
||||
| 本科生通知 | 研究生通知 | 教工通知 | 全体通知 | 学院通知 | 学院新闻 | 学院活动 |
|
||||
| ---------- | ---------- | -------- | -------- | -------- | -------- | -------- |
|
||||
| bkstz | yjstz | jgtz | qttz | xwdt | xyxw | xyhd |
|
||||
|
||||
注意: `qttz` 与 `xwdt` 在原网站等价.
|
||||
|
||||
</route>
|
||||
|
||||
## 传统媒体
|
||||
|
||||
### 央视新闻
|
||||
|
|
|
|||
|
|
@ -600,6 +600,9 @@ router.get('/dlu/jiaowu/news', require('./routes/universities/dlu/jiaowu/news'))
|
|||
router.get('/dgut/jwc/:type?', require('./routes/universities/dgut/jwc'));
|
||||
router.get('/dgut/xsc/:type?', require('./routes/universities/dgut/xsc'));
|
||||
|
||||
// 同济大学
|
||||
router.get('/tju/sse/:type?', require('./routes/universities/tju/sse/notice'));
|
||||
|
||||
// ifanr
|
||||
router.get('/ifanr/:channel?', require('./routes/ifanr/index'));
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,34 @@
|
|||
const axios = require('../../../../utils/axios'); // get web content
|
||||
const cheerio = require('cheerio'); // html parser
|
||||
|
||||
const domain = 'http://sse.tongji.edu.cn';
|
||||
|
||||
module.exports = async function get_article(url) {
|
||||
if (/^\/.*$/.test(url)) {
|
||||
url = domain + url;
|
||||
}
|
||||
const response = await axios({
|
||||
method: 'get',
|
||||
url: url,
|
||||
});
|
||||
const data = response.data;
|
||||
|
||||
const $ = cheerio.load(data);
|
||||
const title = $('div.view-title').text();
|
||||
const pub_date_raw = $('div.view-info').text();
|
||||
const pub_date_parse = /\d{2,4}-\d{1,2}-\d{1,2}/.exec(pub_date_raw);
|
||||
const pub_date = new Date(pub_date_parse[0]).toUTCString();
|
||||
const content = $('div.view-cnt')
|
||||
.html()
|
||||
.replace(/<!\[CDATA\[/g, '<!--')
|
||||
.replace(/\]\]>/g, '-->')
|
||||
.replace(/href="\//g, 'href="' + domain + '/');
|
||||
|
||||
const item = {
|
||||
title: title,
|
||||
pubDate: pub_date,
|
||||
link: url,
|
||||
description: content,
|
||||
};
|
||||
return item;
|
||||
};
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
// Warning: The author still knows nothing about javascript!
|
||||
|
||||
// params:
|
||||
// type: notification type
|
||||
|
||||
const axios = require('../../../../utils/axios'); // get web content
|
||||
const cheerio = require('cheerio'); // html parser
|
||||
const get_article = require('./_article');
|
||||
|
||||
const base_url = 'http://sse.tongji.edu.cn/data/list/$type$';
|
||||
module.exports = async (ctx) => {
|
||||
const type = ctx.params.type || 'xwdt';
|
||||
|
||||
const list_url = base_url.replace('$type$', type);
|
||||
const response = await axios({
|
||||
method: 'get',
|
||||
url: list_url,
|
||||
});
|
||||
const data = response.data; // content is html format
|
||||
const $ = cheerio.load(data);
|
||||
|
||||
// get urls
|
||||
const detail_urls = [];
|
||||
|
||||
const a = $('ul.data-list').find('a');
|
||||
|
||||
for (let i = 0; i < a.length; ++i) {
|
||||
const tmp = $(a[i]).attr('href');
|
||||
detail_urls.push(tmp);
|
||||
}
|
||||
|
||||
// get articles
|
||||
const article_list = await Promise.all(detail_urls.map((url) => get_article(url)));
|
||||
|
||||
// feed the data
|
||||
ctx.state.data = {
|
||||
title: '同济大学软件学院',
|
||||
link: list_url,
|
||||
item: article_list,
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue