zhihu activities
This commit is contained in:
parent
575893dbfa
commit
daa0eb0280
|
|
@ -33,6 +33,7 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇
|
|||
- 作者
|
||||
- 知乎
|
||||
- 收藏夹
|
||||
- 用户动态
|
||||
- 自如
|
||||
- 房源
|
||||
- 快递
|
||||
|
|
|
|||
|
|
@ -255,6 +255,14 @@ s
|
|||
|
||||
参数: id,收藏夹 id,可在收藏夹页面 URL 中找到
|
||||
|
||||
#### 用户动态
|
||||
|
||||
举例: https://rss.prprpr.me/zhihu/people/activities/diygod
|
||||
|
||||
路由: `/zhihu/people/activities/:id`
|
||||
|
||||
参数: id,用户 id,可在用户主页 URL 中找到
|
||||
|
||||
### 自如
|
||||
|
||||
#### 房源
|
||||
|
|
|
|||
|
|
@ -35,5 +35,6 @@ 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'));
|
||||
|
||||
module.exports = router;
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
const axios = require('axios');
|
||||
const art = require('art-template');
|
||||
const path = require('path');
|
||||
const cheerio = require('cheerio');
|
||||
const config = require('../../config');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const id = ctx.params.id;
|
||||
|
||||
const response = await axios({
|
||||
method: 'get',
|
||||
url: `https://www.zhihu.com/people/${id}/activities`,
|
||||
headers: {
|
||||
'User-Agent': config.ua,
|
||||
'Referer': `https://www.zhihu.com/people/${id}/activities`,
|
||||
'authorization': 'oauth c3cef7c66a1843f8b3a9e6a1e3160e20',
|
||||
'X-API-VERSION': '3.0.40'
|
||||
}
|
||||
});
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
const data = $('#data').data('state').entities;
|
||||
|
||||
const name = data.users[id].name;
|
||||
const list = Object.values(data.activities).sort((a, b) => b.createdTime - a.createdTime);
|
||||
|
||||
ctx.body = art(path.resolve(__dirname, '../../views/rss.art'), {
|
||||
title: `${name}的知乎动态`,
|
||||
link: `https://www.zhihu.com/people/${id}/activities`,
|
||||
description: data.users[id].headline || data.users[id].description,
|
||||
lastBuildDate: new Date().toUTCString(),
|
||||
item: list && list.map((item) => {
|
||||
const type = item.target.schema;
|
||||
const detail = data[`${type}s`][item.target.id];
|
||||
let title;
|
||||
let description;
|
||||
let url;
|
||||
|
||||
switch (type) {
|
||||
case 'answer':
|
||||
title = detail.question.title;
|
||||
description = detail.content;
|
||||
url = `https://www.zhihu.com/question/${detail.question.id}/answer/${detail.id}`;
|
||||
break;
|
||||
case 'article':
|
||||
title = detail.title;
|
||||
description = detail.content;
|
||||
url = `https://zhuanlan.zhihu.com/p/${detail.id}`;
|
||||
break;
|
||||
case 'pin':
|
||||
title = detail.excerptTitle.length > 17 ? detail.excerptTitle.slice(0, 17) + '...' : detail.excerptTitle;
|
||||
description = detail.excerptTitle;
|
||||
url = `https://www.zhihu.com/pin/${detail.id}`;
|
||||
break;
|
||||
case 'question':
|
||||
title = detail.title;
|
||||
description = detail.excerpt;
|
||||
url = `https://www.zhihu.com/question/${detail.id}`;
|
||||
break;
|
||||
}
|
||||
|
||||
return {
|
||||
title: `${item.actionText}: ${title}`,
|
||||
description: description,
|
||||
pubDate: new Date(item.createdTime * 1000).toUTCString(),
|
||||
link: url
|
||||
};
|
||||
}),
|
||||
});
|
||||
};
|
||||
Loading…
Reference in New Issue