feat(route): Add Rattibha Twitter user threads (#12630)

This commit is contained in:
Youssif Shaaban Alsager 2023-06-07 15:14:57 +00:00 committed by GitHub
parent 08d894548a
commit bd759b49d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 68 additions and 0 deletions

View File

@ -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

View File

@ -0,0 +1,3 @@
module.exports = {
'/user/:user': ['yshalsager'],
};

13
lib/v2/rattibha/radar.js Normal file
View File

@ -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',
},
],
},
};

View File

@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/user/:user', require('./user'));
};

43
lib/v2/rattibha/user.js Normal file
View File

@ -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,
};
};