diff --git a/docs/README.md b/docs/README.md index 958cfb450..29a833e38 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1385,6 +1385,18 @@ category 列表: +### 同济大学 + + + +| 本科生通知 | 研究生通知 | 教工通知 | 全体通知 | 学院通知 | 学院新闻 | 学院活动 | +| ---------- | ---------- | -------- | -------- | -------- | -------- | -------- | +| bkstz | yjstz | jgtz | qttz | xwdt | xyxw | xyhd | + +注意: `qttz` 与 `xwdt` 在原网站等价. + + + ## 传统媒体 ### 央视新闻 diff --git a/router.js b/router.js index 92c95dfbd..81ecd322e 100644 --- a/router.js +++ b/router.js @@ -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')); diff --git a/routes/universities/tju/sse/_article.js b/routes/universities/tju/sse/_article.js new file mode 100644 index 000000000..f4f0a0ba1 --- /dev/null +++ b/routes/universities/tju/sse/_article.js @@ -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(//g, '-->') + .replace(/href="\//g, 'href="' + domain + '/'); + + const item = { + title: title, + pubDate: pub_date, + link: url, + description: content, + }; + return item; +}; diff --git a/routes/universities/tju/sse/notice.js b/routes/universities/tju/sse/notice.js new file mode 100644 index 000000000..0745b5c59 --- /dev/null +++ b/routes/universities/tju/sse/notice.js @@ -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, + }; +};