From 3398fdec327530735f2dfd6b08ad292bc0654d46 Mon Sep 17 00:00:00 2001 From: DIYgod Date: Fri, 11 May 2018 15:26:41 +0800 Subject: [PATCH] RSS: zhihu answers --- README.md | 1 + docs/README.md | 8 ++++++++ router.js | 1 + routes/zhihu/answers.js | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 42 insertions(+) create mode 100644 routes/zhihu/answers.js diff --git a/README.md b/README.md index b0a1b8b05..074ab3430 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇 - 知乎 - 收藏夹 - 用户动态 + - 用户回答 - 专栏 - 自如 - 房源 diff --git a/docs/README.md b/docs/README.md index cf8aa5066..63ca0d3ae 100644 --- a/docs/README.md +++ b/docs/README.md @@ -292,6 +292,14 @@ s 参数: id,用户 id,可在用户主页 URL 中找到 +### 用户回答 + +举例: [https://rss.now.sh/zhihu/people/answers/diygod](https://rss.now.sh/zhihu/people/answers/diygod) + +路由: `/zhihu/people/answers/:id` + +参数: id,用户 id,可在用户主页 URL 中找到 + ### 专栏 举例: [https://rss.now.sh/zhihu/zhuanlan/googledevelopers](https://rss.now.sh/zhihu/zhuanlan/googledevelopers) diff --git a/router.js b/router.js index c270de770..2d98ba033 100644 --- a/router.js +++ b/router.js @@ -51,6 +51,7 @@ router.get('/jianshu/user/:id', require('./routes/jianshu/user')); // // 知乎 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')); // // 贴吧 diff --git a/routes/zhihu/answers.js b/routes/zhihu/answers.js new file mode 100644 index 000000000..288c55be8 --- /dev/null +++ b/routes/zhihu/answers.js @@ -0,0 +1,32 @@ +const axios = require('axios'); +const template = require('../../utils/template'); +const config = require('../../config'); + +module.exports = async (ctx) => { + const id = ctx.params.id; + + const response = await axios({ + method: 'get', + url: `https://www.zhihu.com/api/v4/members/${id}/answers?include=data%5B*%5D.is_normal%2Cadmin_closed_comment%2Creward_info%2Cis_collapsed%2Cannotation_action%2Cannotation_detail%2Ccollapse_reason%2Ccollapsed_by%2Csuggest_edit%2Ccomment_count%2Ccan_comment%2Ccontent%2Cvoteup_count%2Creshipment_settings%2Ccomment_permission%2Cmark_infos%2Ccreated_time%2Cupdated_time%2Creview_info%2Cquestion%2Cexcerpt%2Crelationship.is_authorized%2Cvoting%2Cis_author%2Cis_thanked%2Cis_nothelp%3Bdata%5B*%5D.author.badge%5B%3F(type%3Dbest_answerer)%5D.topics&offset=0&limit=7&sort_by=created`, + headers: { + 'User-Agent': config.ua, + 'Referer': `https://www.zhihu.com/people/${id}/answers`, + 'authorization': 'oauth c3cef7c66a1843f8b3a9e6a1e3160e20', + 'X-API-VERSION': '3.0.40' + } + }); + + const data = response.data.data; + + ctx.body = template({ + title: `${data[0].author.name}的知乎回答`, + link: `https://www.zhihu.com/people/${id}/answers`, + description: data[0].author.headline || data[0].author.description, + item: data && data.map((item) => ({ + title: item.question.title, + description: item.content, + pubDate: new Date(item.created_time * 1000).toUTCString(), + link: `https://www.zhihu.com/question/${item.question.id}/answer/${item.id}` + })), + }); +};