feat(route): Add Rattibha Twitter user threads (#12630)
This commit is contained in:
parent
08d894548a
commit
bd759b49d6
|
|
@ -376,6 +376,12 @@ Only for self-hosted
|
|||
|
||||
<RouteEn author="TonyRL" path="/plurk/user/:user" example="/plurk/user/plurkoffice" :paramsDesc="['User ID, can be found in URL']" radar="1" rssbud="1"/>
|
||||
|
||||
## Rattibha
|
||||
|
||||
### User Threads
|
||||
|
||||
<RouteEn author="yshalsager" example="/rattibha/user/elonmusk" path="/rattibha/user/:user" :paramsDesc="['Twitter username, without @']" radar="1" rssbud="1"/>
|
||||
|
||||
## Telegram
|
||||
|
||||
### Channel
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = {
|
||||
'/user/:user': ['yshalsager'],
|
||||
};
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
module.exports = {
|
||||
'rattibha.com': {
|
||||
_name: 'رتبها - Rattibha',
|
||||
'.': [
|
||||
{
|
||||
title: 'User Threads',
|
||||
docs: 'https://docs.rsshub.app/en/social-media.html#rattibha',
|
||||
source: ['/:user'],
|
||||
target: '/rattibha/user/:user',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = function (router) {
|
||||
router.get('/user/:user', require('./user'));
|
||||
};
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
const got = require('@/utils/got');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const baseUrl = 'https://rattibha.com';
|
||||
const { user: twitterUser } = ctx.params;
|
||||
|
||||
const {
|
||||
data: { user: userData },
|
||||
} = await got(`${baseUrl}/user?id=${twitterUser}`, {
|
||||
headers: {
|
||||
accept: 'application/json',
|
||||
},
|
||||
});
|
||||
const { data: userThreads } = await got(`${baseUrl}/u_threads?id=${userData.account_user_id}`, { headers: { accept: 'application/json' } });
|
||||
|
||||
// extract the relevant data from the API response
|
||||
const list = userThreads.map((item) => ({
|
||||
title: item.thread.t.info.text,
|
||||
link: `${baseUrl}/thread/${item.thread_id}`,
|
||||
pubDate: parseDate(item.thread.created_at),
|
||||
updated: parseDate(item.thread.updated_at),
|
||||
author: userData.name,
|
||||
api_link: `${baseUrl}/threads?id=${item.thread_id}`,
|
||||
}));
|
||||
|
||||
// Get tweet full text
|
||||
const items = await Promise.all(
|
||||
list.map((item) =>
|
||||
ctx.cache.tryGet(item.api_link, async () => {
|
||||
const { data: threads } = await got(item.api_link, { headers: { accept: 'application/json' } });
|
||||
item.description = threads.reduce((accumulator, tweet) => `${accumulator}${tweet.tweet_detail.info.text}<br>`, '');
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `سلاسل تغريدات ${twitterUser}`,
|
||||
link: `${baseUrl}/${twitterUser}`,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue