Skip to content

Commit

Permalink
feat: twitter keyword RSS, close #156
Browse files Browse the repository at this point in the history
  • Loading branch information
DIYgod committed Nov 29, 2019
1 parent 5a2a37f commit eabf2c7
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 4 deletions.
14 changes: 10 additions & 4 deletions assets/radar-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,28 +110,34 @@
docs: 'https://docs.rsshub.app/social-media.html#twitter',
source: '/:id',
target: '/twitter/user/:id',
verification: (params) => params.id !== 'home' && params.id !== 'explore' && params.id !== 'notifications' && params.id !== 'messages' && params.id !== 'explore',
verification: (params) => params.id !== 'home' && params.id !== 'explore' && params.id !== 'notifications' && params.id !== 'messages' && params.id !== 'explore' && params.id !== 'search',
},
{
title: '用户关注时间线',
docs: 'https://docs.rsshub.app/social-media.html#twitter',
source: '/:id',
target: '/twitter/followings/:id',
verification: (params) => params.id !== 'home' && params.id !== 'explore' && params.id !== 'notifications' && params.id !== 'messages' && params.id !== 'explore',
verification: (params) => params.id !== 'home' && params.id !== 'explore' && params.id !== 'notifications' && params.id !== 'messages' && params.id !== 'explore' && params.id !== 'search',
},
{
title: '用户喜欢列表',
docs: 'https://docs.rsshub.app/social-media.html#twitter',
source: '/:id',
target: '/twitter/likes/:id',
verification: (params) => params.id !== 'home' && params.id !== 'explore' && params.id !== 'notifications' && params.id !== 'messages' && params.id !== 'explore',
verification: (params) => params.id !== 'home' && params.id !== 'explore' && params.id !== 'notifications' && params.id !== 'messages' && params.id !== 'explore' && params.id !== 'search',
},
{
title: '列表时间线',
docs: 'https://docs.rsshub.app/social-media.html#twitter',
source: '/:id/lists/:name',
target: '/twitter/list/:id/:name',
verification: (params) => params.id !== 'home' && params.id !== 'explore' && params.id !== 'notifications' && params.id !== 'messages' && params.id !== 'explore',
verification: (params) => params.id !== 'home' && params.id !== 'explore' && params.id !== 'notifications' && params.id !== 'messages' && params.id !== 'explore' && params.id !== 'search',
},
{
title: '关键词',
docs: 'https://docs.rsshub.app/social-media.html#twitter',
source: '/search',
target: (params, url) => `/twitter/keyword/${new URL(url).searchParams.get('q')}`,
},
],
},
Expand Down
4 changes: 4 additions & 0 deletions docs/en/social-media.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ This route requires Twitter token's corresponding id, therefore it's only availb

<RouteEn author="xyqfer" example="/twitter/likes/DIYgod" path="/twitter/likes/:id" :paramsDesc="['user name']"/>

### Keyword

<Route author="DIYgod" example="/twitter/keyword/RSSHub" path="/twitter/keyword/:keyword" :paramsDesc="['keyword']" radar="1"/>

## Youtube

### User
Expand Down
4 changes: 4 additions & 0 deletions docs/social-media.md
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,10 @@ Tiny Tiny RSS 会给所有 iframe 元素添加 `sandbox="allow-scripts"` 属性

<Route author="xyqfer" example="/twitter/likes/DIYgod" path="/twitter/likes/:id" :paramsDesc="['用户名']" radar="1"/>

### 关键词

<Route author="DIYgod" example="/twitter/keyword/RSSHub" path="/twitter/keyword/:keyword" :paramsDesc="['关键词']" radar="1"/>

## VueVlog

### 用户
Expand Down
1 change: 1 addition & 0 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ router.get('/twitter/user/:id', require('./routes/twitter/user'));
router.get('/twitter/list/:id/:name', require('./routes/twitter/list'));
router.get('/twitter/likes/:id', require('./routes/twitter/likes'));
router.get('/twitter/followings/:id', require('./routes/twitter/followings'));
router.get('/twitter/keyword/:keyword', require('./routes/twitter/keyword'));

// Instagram
router.get('/instagram/user/:id', require('./routes/instagram/user'));
Expand Down
24 changes: 24 additions & 0 deletions lib/routes/twitter/keyword.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const utils = require('./utils');
const config = require('@/config').value;

module.exports = async (ctx) => {
if (!config.twitter || !config.twitter.consumer_key || !config.twitter.consumer_secret) {
throw 'Twitter RSS is disabled due to the lack of <a href="https://docs.rsshub.app/install/#%E9%83%A8%E5%88%86-rss-%E6%A8%A1%E5%9D%97%E9%85%8D%E7%BD%AE">relevant config</a>';
}
const keyword = ctx.params.keyword;
const result = await utils.getTwit().get('search/tweets', {
q: encodeURIComponent(keyword),
count: 50,
tweet_mode: 'extended',
result_type: 'recent',
});
const data = result.data;

ctx.state.data = {
title: `Twitter keyWOrd - ${keyword}`,
link: `https://twitter.com/search?q=${encodeURIComponent(keyword)}`,
item: utils.ProcessFeed({
data: data.statuses,
}),
};
};

0 comments on commit eabf2c7

Please sign in to comment.