From be67fb19aa8b7b773df8235c3bfae19435dd3961 Mon Sep 17 00:00:00 2001 From: csi0n Date: Fri, 4 May 2018 20:30:57 +0800 Subject: [PATCH 1/6] #68 Add dockone support --- router.js | 3 +++ routes/dockone/weekly.js | 44 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 routes/dockone/weekly.js diff --git a/router.js b/router.js index e10c7a7c7..d566ef467 100644 --- a/router.js +++ b/router.js @@ -74,4 +74,7 @@ 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')); + module.exports = router; diff --git a/routes/dockone/weekly.js b/routes/dockone/weekly.js new file mode 100644 index 000000000..e1cb23bb9 --- /dev/null +++ b/routes/dockone/weekly.js @@ -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(), + }); +}; From ddf183dfe447b505a74473bf6f65626835a16ce7 Mon Sep 17 00:00:00 2001 From: DIYgod Date: Fri, 4 May 2018 22:57:04 +0800 Subject: [PATCH 2/6] update docs for Dockone --- README.md | 2 ++ docs/README.md | 10 ++++++++++ router.js | 2 +- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1183c3fb4..ec1996977 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,8 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇 - 无聊图 - 喷嚏 - 图卦 +- Dockone + - 周报 ## 参与我们 diff --git a/docs/README.md b/docs/README.md index 48463280f..7e650cdf3 100644 --- a/docs/README.md +++ b/docs/README.md @@ -449,6 +449,16 @@ city: 城市的中文名,可选,默认北京 参数: 无 +### Dockone + +#### 周报 + +举例: https://rss.now.sh/dockone/weekly + +路由: `/dockone/weekly` + +参数: 无 + ## 搭建 环境:需要 Node.js v7.6.0 或更高版本,若启用 Redis 缓存需要先启动 Redis diff --git a/router.js b/router.js index d566ef467..00046b9e8 100644 --- a/router.js +++ b/router.js @@ -75,6 +75,6 @@ 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('/dockone/weekly', require('./routes/dockone/weekly')); module.exports = router; From e83a5814cb963862eee457e825932e2deb329bdf Mon Sep 17 00:00:00 2001 From: DIYgod Date: Fri, 4 May 2018 23:45:20 +0800 Subject: [PATCH 3/6] fix weibo user pubDate --- routes/weibo/user.js | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/routes/weibo/user.js b/routes/weibo/user.js index 051878d2e..ed5129960 100644 --- a/routes/weibo/user.js +++ b/routes/weibo/user.js @@ -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}` }; }), From f2ec6a0405a7bf590db5da5b6ef86d609ccfa0fc Mon Sep 17 00:00:00 2001 From: jjeejj Date: Sat, 5 May 2018 10:21:04 +0800 Subject: [PATCH 4/6] fix middleware/utf8.js file bug --- middleware/utf8.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/middleware/utf8.js b/middleware/utf8.js index cca1a34a8..c513eb2da 100644 --- a/middleware/utf8.js +++ b/middleware/utf8.js @@ -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; }; From 4d8b0646f0b6a06fd13563b5c1f07d175942c4b5 Mon Sep 17 00:00:00 2001 From: jjeejj Date: Sat, 5 May 2018 14:53:34 +0800 Subject: [PATCH 5/6] =?UTF-8?q?fixed=20#60=20=E8=87=AA=E5=A6=82=E6=88=BF?= =?UTF-8?q?=E6=BA=90=E8=BF=94=E5=9B=9E=E6=95=B0=E6=8D=AE=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routes/ziroom/room.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/routes/ziroom/room.js b/routes/ziroom/room.js index 45f7bf7e5..d3d298a2f 100644 --- a/routes/ziroom/room.js +++ b/routes/ziroom/room.js @@ -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` })), }); -}; \ No newline at end of file +}; From e7b22f7684c7a03436977bd60f9e7ce42cd807c0 Mon Sep 17 00:00:00 2001 From: Ir1dXD Date: Sat, 5 May 2018 19:30:29 +0800 Subject: [PATCH 6/6] Fix #78 update link for zhihu collections --- routes/zhihu/collection.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/routes/zhihu/collection.js b/routes/zhihu/collection.js index 4e0c3b33f..c3375b48a 100644 --- a/routes/zhihu/collection.js +++ b/routes/zhihu/collection.js @@ -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(), }); -}; \ No newline at end of file +};