Merge branch 'master' into master

This commit is contained in:
DIYgod
2018-05-05 23:02:11 +08:00
committed by GitHub
8 changed files with 105 additions and 9 deletions
+2
View File
@@ -58,6 +58,8 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇
- 无聊图
- 喷嚏
- 图卦
- Dockone
- 周报
## 参与我们
+16 -2
View File
@@ -449,15 +449,29 @@ city: 城市的中文名,可选,默认北京
参数: 无
### Dockone
#### 周报
举例: https://rss.now.sh/dockone/weekly
路由: `/dockone/weekly`
参数: 无
### 腾讯吐个槽
#### 吐槽新帖
举例: https://rss.now.sh/tucaoqq/post/28564/CdRI0728
路由: `/tucaoqq/post`
路由: `/tucaoqq/post/:project/:key`
参数: project 产品ID key 产品密钥
参数
project: 产品ID
key: 产品密钥
## 搭建
+1 -1
View File
@@ -2,5 +2,5 @@
// https://stackoverflow.com/questions/1497885/remove-control-characters-from-php-string/1497928#1497928
module.exports = async (ctx, next) => {
await next();
ctx.body = ctx.body.replace(/[\x00-\x1F\x7F]/g, '');
ctx.body = ctx.body?ctx.body.replace(/[\x00-\x1F\x7F]/g, ''):ctx.body;
};
+4
View File
@@ -74,6 +74,10 @@ router.get('/jandan/pic', require('./routes/jandan/pic'));
// 喷嚏
router.get('/dapenti/tugua', require('./routes/dapenti/tugua'));
// Dockone
router.get('/dockone/weekly', require('./routes/dockone/weekly'));
// 腾讯吐个槽
router.get('/tucaoqq/post/:project/:key', require('./routes/tucaoqq/post'));
module.exports = router;
+44
View File
@@ -0,0 +1,44 @@
const axios = require('axios');
const art = require('art-template');
const path = require('path');
const cheerio = require('cheerio');
const config = require('../../config');
function replaceEmpty(str) {
return str.replace(' ','');
}
const baseUrl='http://weekly.dockone.io'
module.exports = async (ctx) => {
const url = `${baseUrl}/issues`;
const response = await axios({
method: 'get',
url: url,
headers: {
'User-Agent': config.ua,
Referer: url
}
});
const data = response.data;
const $ = cheerio.load(data);
const list = $('ul.i.issues>li');
ctx.body = art(path.resolve(__dirname, '../../views/rss.art'), {
title: $('title').text(),
link: url,
description: $('meta[name="description"]').attr('content') || $('title').text(),
lastBuildDate: new Date().toUTCString(),
item: list && list.map((item,index) => {
item=$(index);
return {
title:`${replaceEmpty(item.find('a>h3>time').text())}[${replaceEmpty(item.find('a>h3>strong').text())}]`,
description:item.find('a>ul>li').text(),
link:`${baseUrl}${item.find('a').attr('href')}`
};
}).get(),
});
};
+30 -1
View File
@@ -40,6 +40,35 @@ function format (status) {
return temp;
}
// 格式化时间
function getTime (html) {
console.log(html);
let math;
let date = new Date();
if (/(\d+)分钟前/.exec(html)) {
math = /(\d+)分钟前/.exec(html);
date.setMinutes(date.getMinutes() - math[1]);
return date.toUTCString();
} else if (/(\d+)小时前/.exec(html)) {
math = /(\d+)小时前/.exec(html);
date.setHours(date.getHours() - math[1]);
return date.toUTCString();
} else if (/今天 (\d+):(\d+)/.exec(html)) {
math = /今天 (\d+):(\d+)/.exec(html);
date = new Date(date.getFullYear(), date.getMonth(), date.getDate(), math[1], math[2]);
return date.toUTCString();
} else if (/昨天 (\d+):(\d+)/.exec(html)) {
math = /昨天 (\d+):(\d+)/.exec(html);
date = new Date(date.getFullYear(), date.getMonth(), date.getDate() - 1, math[1], math[2]);
return date.toUTCString();
} else if (/(\d+)月(\d+)日 (\d+):(\d+)/.exec(html)) {
math = /(\d+)月(\d+)日 (\d+):(\d+)/.exec(html);
date = new Date(date.getFullYear(), math[1] - 1, parseInt(math[2]), math[3], math[4]);
return date.toUTCString();
}
return html;
}
module.exports = async (ctx) => {
const uid = ctx.params.uid;
@@ -73,7 +102,7 @@ module.exports = async (ctx) => {
return {
title: title.length > 24 ? title.slice(0, 24) + '...' : title,
description: format(item.mblog),
pubDate: new Date(item.mblog.created_at.length === 5 ? `${new Date().getFullYear()}-${item.mblog.created_at}` : item.mblog.created_at).toUTCString(),
pubDate: getTime(item.mblog.created_at),
link: `https://weibo.com/${uid}/${item.mblog.bid}`
};
}),
+4 -2
View File
@@ -27,11 +27,13 @@ module.exports = async (ctx) => {
lastBuildDate: new Date().toUTCString(),
item: list && list.map((index, item) => {
item = $(item);
let linkUrl = item.find('.zm-item-title a').attr('href');
if (linkUrl.startsWith('/')) linkUrl = 'https://www.zhihu.com' + linkUrl;
return {
title: item.find('.zm-item-title a').text(),
description: `内容:${item.find('textarea').text()}`,
link: `https://www.zhihu.com${item.find('.zm-item-title a').attr('href')}`
link: linkUrl
};
}).get(),
});
};
};
+4 -3
View File
@@ -27,8 +27,9 @@ module.exports = async (ctx) => {
'step': 0
}),
});
const data = response.data.data;
let data = response.data.data; //当查询的结果不存在时,该 data 是个对象 { info: '数据加载完毕' }
//判断数据的类型,如果有数据就是数组类型的,没有数据的话,就赋值为空数组
data = (data instanceof Array) ? data : [{title:"我们找不到任何与您的搜索条件匹配的结果,但是调整您的搜索条件可能会有所帮助",room_name:"",list_img:"",city:"",id:""}];
ctx.body = art(path.resolve(__dirname, '../../views/rss.art'), {
title: `自如的${keyword}${iswhole ? '整租' : '合租'}${room}室房源`,
@@ -41,4 +42,4 @@ module.exports = async (ctx) => {
link: `http://${domain}/${city.toUpperCase()}/room/${item.id}.html`
})),
});
};
};