Skip to content

Commit

Permalink
feat(route): tass (#14426)
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyRL authored Feb 7, 2024
1 parent 673aad4 commit e62362a
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/v2/tass/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/:category?': ['TonyRL'],
};
58 changes: 58 additions & 0 deletions lib/v2/tass/news.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');

module.exports = async (ctx) => {
const { category = 'politics' } = ctx.params;

const { data: categoryPage, url: link } = await got(`https://tass.com/${category}`);
const $ = cheerio.load(categoryPage);

const sectionId = $('.container .section-page')
.attr('ng-init')
.match(/sectionId\s*=\s*(\d+?);/);

const { data: response } = await got.post('https://tass.com/userApi/categoryNewsList', {
json: {
sectionId: sectionId[1],
limit: 20,
type: 'all',
},
});

const list = response.newsList.map((item) => ({
title: item.title,
description: item.lead,
link: `https://tass.com${item.link}`,
pubDate: parseDate(item.date, 'X'),
}));

const items = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const { data: response } = await got(item.link);
const $ = cheerio.load(response);

$('.news-media img').each((_, ele) => {
if (ele.attribs.src) {
ele.attribs.src = ele.attribs.src.replaceAll('/width/1020_b9261fa1', '');
}
});

item.description = $('.news-header__lead').prop('outerHTML') + ($('.news-media').prop('outerHTML') ?? '') + $('.text-block').html();

return item;
})
)
);

ctx.state.data = {
title: $('head title').text(),
link,
language: 'en',
image: $('head meta[property="og:image"]').attr('content'),
icon: $('head link[rel="apple-touch-icon"]').attr('href'),
logo: $('head link[rel="apple-touch-icon"]').attr('href'),
item: items,
};
};
13 changes: 13 additions & 0 deletions lib/v2/tass/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
'tass.com': {
_name: 'Russian News Agency TASS',
'.': [
{
title: 'News',
docs: 'https://docs.rsshub.app/routes/traditional-media.html#russian-news-agency-tass',
source: ['/:category'],
target: '/tass/:category',
},
],
},
};
3 changes: 3 additions & 0 deletions lib/v2/tass/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/:category?', require('./news'));
};
10 changes: 10 additions & 0 deletions website/docs/routes/traditional-media.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,16 @@ This route adds the missing photo and Link element. (Offical RSS doesn't have Li
(`opencc` 是 RSSHub 的通用参数,详情请参阅 [「中文简繁体转换」](/parameter#中文简繁体转换))
</Route>

## Russian News Agency TASS {#russian-news-agency-tass}

### News {#russian-news-agency-tass-news}

<Route author="TonyRL" example="/tass/politics" path="/tass/:category?" paramsDesc={['Category, can be found in URL, `politics` by default']} radar="1">
| Russian Politics & Diplomacy | World | Business & Economy | Military & Defense | Science & Space | Emergencies | Society & Culture | Press Review | Sports |
| ---------------------------- | ----- | ------------------ | ------------------ | --------------- | ----------- | ----------------- | ------------ | ------ |
| politics | world | economy | defense | science | emergencies | society | pressreview | sports |
</Route>

## Solidot {#solidot}

### 最新消息 {#solidot-zui-xin-xiao-xi}
Expand Down

0 comments on commit e62362a

Please sign in to comment.