add MIT Grad Blog (#2017)

This commit is contained in:
Chenyang Shi 2019-04-30 00:23:32 +08:00 committed by DIYgod
parent 1bf2a9c724
commit f869d9db01
3 changed files with 76 additions and 0 deletions

View File

@ -708,3 +708,11 @@ https://rsshub.app/**nuist**/`bulletin` 或 https://rsshub.app/**nuist**/`bullet
## 广东海洋大学
<Route name="广东海洋大学" author="Xiaotouming" example="/gdoujwc" path="/gdoujwc"/>
## MIT
<Route name="MIT graduateadmissions's all blogs" author="LogicJake" example="/mit/graduateadmissions/index/all" path="/universities/mit/graduateadmissions/index/all"/>
<Route name="MIT graduateadmissions's blogs by department" author="LogicJake" example="/mit/graduateadmissions/department/eecs" path="/universities/mit/graduateadmissions/department/:name" :paramsDesc="['department name which can be found in url']"/>
<Route name="MIT graduateadmissions's blogs by category" author="LogicJake" example="/mit/graduateadmissions/category/beyond-the-lab" path="/universities/mit/graduateadmissions/category/:name" :paramsDesc="['category name which can be found in url']"/>

View File

@ -1290,6 +1290,9 @@ router.get('/mlhang', require('./routes/mlhang/latest'));
// PlayStation Store
router.get('/ps/list/:gridName', require('./routes/ps/list'));
// MIT
router.get('/mit/graduateadmissions/:type/:name', require('./routes/universities/mit/graduateadmissions'));
// 毕马威
router.get('/kpmg/insights', require('./routes/kpmg/insights'));

View File

@ -0,0 +1,65 @@
const axios = require('../../../utils/axios');
const cheerio = require('cheerio');
const host = 'https://gradadmissions.mit.edu';
module.exports = async (ctx) => {
const type = ctx.params.type;
const name = ctx.params.name;
let link = host + '';
switch (type) {
case 'index':
link = host + '/blog';
break;
case 'category':
link = host + `/blog/browse/category/${name}`;
break;
case 'department':
link = host + `/blog/browse/department/${name}`;
break;
}
const response = await axios.get(link);
const $ = cheerio.load(response.data);
const title = $('#page-title').text();
const list = $('div.views-row');
const out = await Promise.all(
list
.slice(0, 10)
.map(async (_, elem) => {
const $elem = $(elem);
const title = $elem.find('h3.item-title a').text() + '-' + $elem.find('h4.item-subtitle').text();
const itemUrl = host + $elem.find('h3.item-title a').attr('href');
const author = $elem.find('div.item-info a').text();
const cache = await ctx.cache.get(itemUrl);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
const response = await axios.get(itemUrl);
const $$ = cheerio.load(response.data);
const description = $$('div.field-name-body div.field-items')
.html()
.replace(/src="/g, `src="${host}`);
const single = {
title: title,
link: itemUrl,
author: author,
description: description,
};
ctx.cache.set(itemUrl, JSON.stringify(single), 24 * 60 * 60);
return Promise.resolve(single);
})
.get()
);
ctx.state.data = {
title: `${title}-MIT`,
link: link,
item: out,
};
};