From d73cb0c06561eaa702cee6c27e53ed639be981d6 Mon Sep 17 00:00:00 2001 From: Jimmy Wang Date: Wed, 16 May 2018 10:58:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=9F=A5=E4=B9=8E=E6=97=A5?= =?UTF-8?q?=E6=8A=A5=20(#139)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 新增知乎日报 * update zhihu daily --- README.md | 1 + docs/README.md | 6 ++++++ router.js | 1 + routes/zhihu/daily.js | 40 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 48 insertions(+) create mode 100644 routes/zhihu/daily.js diff --git a/README.md b/README.md index 3ea1f850a6..d244c8ca29 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,7 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇 - 用户动态 - 用户回答 - 专栏 + - 知乎日报 - 自如 - 房源 - 快递 diff --git a/docs/README.md b/docs/README.md index c5e93fc121..e06f4395d5 100644 --- a/docs/README.md +++ b/docs/README.md @@ -392,6 +392,12 @@ order: 排序方式,live_time 开播时间,online 人气 参数: id,专栏 id,可在专栏主页 URL 中找到 +### 知乎日报 + +举例:[https://rsshub.app/zhihu/daily](https://rsshub.app/zhihu/daily) + +路由:`/zhihu/daily` + ## 自如 ### 房源 diff --git a/router.js b/router.js index 53d5b84769..cbfa4f9c4f 100644 --- a/router.js +++ b/router.js @@ -58,6 +58,7 @@ router.get('/zhihu/collection/:id', require('./routes/zhihu/collection')); router.get('/zhihu/people/activities/:id', require('./routes/zhihu/activities')); router.get('/zhihu/people/answers/:id', require('./routes/zhihu/answers')); router.get('/zhihu/zhuanlan/:id', require('./routes/zhihu/zhuanlan')); +router.get('/zhihu/daily', require('./routes/zhihu/daily')) // 贴吧 router.get('/tieba/forum/:kw', require('./routes/tieba/forum')); diff --git a/routes/zhihu/daily.js b/routes/zhihu/daily.js new file mode 100644 index 0000000000..25a7ec9dd9 --- /dev/null +++ b/routes/zhihu/daily.js @@ -0,0 +1,40 @@ +const axios = require('axios'); +const config = require('../../config'); + +module.exports = async (ctx) => { + const today = await axios({ + method: 'get', + url: 'https://news-at.zhihu.com/api/2/news/latest', // 旧版api,可以获取文章的url。参考:https://github.com/izzyleung/ZhihuDailyPurify/wiki/%E7%9F%A5%E4%B9%8E%E6%97%A5%E6%8A%A5-API-%E5%88%86%E6%9E%90 + headers: { + 'User-Agent': config.ua, + 'Referer': 'https://daily.zhihu.com' // 不知道应该写什么比较好,随便写一个吧 + } + }); + const d = new Date(); + // todayfmt: YYYYMMDD + const todayfmt = `${d.getFullYear()}${d.getMonth() > 8 ? d.getMonth() + 1 : '0' + (d.getMonth() + 1)}${d.getDate()}`; + + const yesterday = await axios({ + method: 'get', + url: `https://news-at.zhihu.com/api/2/news/before/${todayfmt}`, // 旧版api,可以获取文章的url。参考:https://github.com/izzyleung/ZhihuDailyPurify/wiki/%E7%9F%A5%E4%B9%8E%E6%97%A5%E6%8A%A5-API-%E5%88%86%E6%9E%90 + headers: { + 'User-Agent': config.ua, + 'Referer': 'https://daily.zhihu.com' + } + }); + + const items = today.data.news.concat(yesterday.data.news); + + ctx.state.data = { + title: '知乎日报', + link: 'https://daily.zhihu.com', + description: '每天3次,每次7分钟', + item: items.map((item) => { + return { + title: item.title, + description: ``, // 暂时没有找到包含正文的api,所以就放一张图吧 + link: item.share_url + }; + }), + }; +};