mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-24 23:12:34 +08:00
feat: add router twitter/trends (#4355)
This commit is contained in:
@@ -148,6 +148,10 @@ This route requires Twitter token's corresponding id, therefore it's only availb
|
||||
|
||||
<RouteEn author="DIYgod" example="/twitter/keyword/RSSHub" path="/twitter/keyword/:keyword" :paramsDesc="['keyword']" radar="1"/>
|
||||
|
||||
### Trends
|
||||
|
||||
<RouteEn author="sakamossan" example="/twitter/trends/23424856" path="/twitter/trends/:woeid?" :paramsDesc="['Yahoo! Where On Earth ID. default to woeid=1 (World Wide)']" radar="1"/>
|
||||
|
||||
## Youtube
|
||||
|
||||
::: tip Tiny Tiny RSS users please notice
|
||||
|
||||
@@ -205,6 +205,7 @@ 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'));
|
||||
router.get('/twitter/trends/:woeid?', require('./routes/twitter/trends'));
|
||||
|
||||
// Instagram
|
||||
router.get('/instagram/user/:id', require('./routes/instagram/user'));
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
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 woeid = ctx.params.woeid || 1; // Global information is available by using 1 as the WOEID
|
||||
const result = await utils.getTwit().get('trends/place', { id: woeid });
|
||||
const [{ trends }] = result.data;
|
||||
|
||||
ctx.state.data = {
|
||||
title: `Twitter Trends on ${woeid}(Yahoo! Where On Earth ID)`,
|
||||
link: `https://twitter.com/i/trends`,
|
||||
item: trends
|
||||
.filter((t) => !t.promoted_content)
|
||||
.map((t) => ({
|
||||
title: t.name,
|
||||
link: t.url,
|
||||
description: t.name + (t.tweet_volume ? ` (${t.tweet_volume})` : ''),
|
||||
})),
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user