Skip to content

Commit

Permalink
feat(route): add counterstrike match results from liquipedia (#13855)
Browse files Browse the repository at this point in the history
* feat(route): add counterstrike match results from liquipedia

* format

* fix: keep pubDate undefined

* fix: unique guid

* fix: docs

* fix: remove unreachable defaults

* refactor: migrate to v2

---------
  • Loading branch information
CookiePieWw authored Nov 23, 2023
1 parent 7eb8cbc commit 96e73ff
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 54 deletions.
2 changes: 1 addition & 1 deletion lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -2116,7 +2116,7 @@ router.get('/sagawa/:id', lazyloadRouteHandler('./routes/sagawa/index'));
router.get('/qnap/release-notes/:id', lazyloadRouteHandler('./routes/qnap/release-notes'));

// Liquipedia
router.get('/liquipedia/dota2/matches/:id', lazyloadRouteHandler('./routes/liquipedia/dota2_matches.js'));
// router.get('/liquipedia/dota2/matches/:id', lazyloadRouteHandler('./routes/liquipedia/dota2_matches.js'));

// 哈尔滨市科技局
router.get('/gov/harbin/kjj', lazyloadRouteHandler('./routes/gov/harbin/kjj'));
Expand Down
50 changes: 0 additions & 50 deletions lib/routes/liquipedia/dota2_matches.js

This file was deleted.

52 changes: 52 additions & 0 deletions lib/v2/liquipedia/cs_matches.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');

module.exports = async (ctx) => {
const team = ctx.params.team;

const rootUrl = 'https://liquipedia.net';
const currentUrl = `${rootUrl}/counterstrike/${team}/Matches`;

const response = await got({
method: 'get',
url: currentUrl,
});

const $ = cheerio.load(response.data);
const list = $('.recent-matches-bg-lose, .recent-matches-bg-win');

const matches = list
.map((_, item) => {
item = $(item);

const getRes = () => {
if (item.attr('class') === 'recent-matches-bg-lose') {
return 'LOSS';
} else {
return 'WIN';
}
};
const result = getRes();

const infoList = item.find('td');

const time = infoList.eq(0).text() + ' ' + infoList.eq(1).text();
const tournament = infoList.eq(6).text();
const score = infoList.eq(7).text();
const opponent = infoList.eq(8).text();

return {
title: `[${result}] ${team} ${score} ${opponent} on ${tournament}`,
description: `${time}, ${team} ${score} ${opponent} on ${tournament}`,
link: currentUrl,
guid: currentUrl + time,
};
})
.get();

ctx.state.data = {
title: `[Counter-Strike] ${team} Match Results From Liquipedia`,
link: currentUrl,
item: matches,
};
};
47 changes: 47 additions & 0 deletions lib/v2/liquipedia/dota2_matches.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');

module.exports = async (ctx) => {
const team = ctx.params.id;
const url = `https://liquipedia.net/dota2/${team}`;
const response = await got({
method: 'get',
url,
});

const data = response.data;

const $ = cheerio.load(data);
const list = $('div.recent-matches > table > tbody > tr[style]');

ctx.state.data = {
title: `Liquipedia Dota2 ${team} Matches`,
link: url,
item: list?.toArray().map((item) => {
item = $(item);
let message = '';
if (item.attr('style') === 'background:rgb(240, 255, 240)') {
message = '胜';
} else if (item.attr('style') === 'background:rgb(249, 240, 242)') {
message = '败';
} else {
message = '平';
}
const date = item.find('td:nth-child(1)').text();
const time = item.find('td:nth-child(2)').text();
const tournament = item.find('td:nth-child(6) > a').text();
const dateTime = parseDate(date + ' ' + time);
const score = item.find('td:nth-child(7)').text();
const vs_team = item.find('td:nth-child(8) > span > span.team-template-text > a').text();

return {
title: `[${message}] ${score} ${vs_team}`,
description: `At ${tournament}, ${team} ${score} ${vs_team}`,
pubDate: dateTime,
link: url,
guid: url + dateTime,
};
}),
};
};
4 changes: 4 additions & 0 deletions lib/v2/liquipedia/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
'/counterstrike/matches/:team': ['CookiePieWw'],
'/dota2/matches/:id': ['wzekin'],
};
19 changes: 19 additions & 0 deletions lib/v2/liquipedia/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = {
'liquipedia.net': {
_name: 'Liquipedia',
'.': [
{
title: 'Counter Strike Match Results',
docs: 'https://docs.rsshub.app/routes/game#liquipedia',
source: ['/counterstrike/:id/Matches', '/dota2/:id'],
target: '/liquipedia/counterstrike/matches/:id',
},
{
title: 'Dota2 战队最近比赛结果',
docs: 'https://docs.rsshub.app/routes/game#liquipedia',
source: ['/dota2/:id'],
target: '/liquipedia/dota2/matches/:id',
},
],
},
};
4 changes: 4 additions & 0 deletions lib/v2/liquipedia/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = (router) => {
router.get('/counterstrike/matches/:team', require('./cs_matches.js'));
router.get('/dota2/matches/:id', require('./dota2_matches.js'));
};
10 changes: 7 additions & 3 deletions website/docs/routes/game.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -318,19 +318,23 @@ So the route is [`/itch/devlogs/teamterrible/the-baby-in-yellow`](https://rsshub

### PES Mobile Announcement {#konami-pes-mobile-announcement}

<Route author="HenryQW" example="/konami/pesmobile/en/ios" path="/konami/pesmobile/:lang?/:os?" paramsDesc={['language, obtained from the URL, eg. zh-cn, zh-tw, en', 'operating systemiOS or Android']}/>
<Route author="HenryQW" example="/konami/pesmobile/en/ios" path="/konami/pesmobile/:lang?/:os?" paramsDesc={['language, obtained from the URL, eg. zh-cn, zh-tw, en', 'operating system, iOS or Android']}/>

## Liquipedia {#liquipedia}

### Dota2 战队最近比赛结果 {#liquipedia-dota2-zhan-dui-zui-jin-bi-sai-jie-guo}

<Route author="wzekin" example="/liquipedia/dota2/matches/Team_Aster" path="liquipedia/dota2/matches/:id" paramsDesc={['战队名称,可在url中找到。例如:https://liquipedia.net/dota2/Team_Aster']}/>
<Route author="wzekin" example="/liquipedia/dota2/matches/Team_Aster" path="/liquipedia/dota2/matches/:id" paramsDesc={['战队名称,可在url中找到。例如:https://liquipedia.net/dota2/Team_Aster']}/>

### Counter Strike Match Results {#liquipedia-cs-match-results}

<Route author="CookiePieWw" example="/liquipedia/counterstrike/matches/G2_Esports" path="/liquipedia/counterstrike/matches/:id" paramsDesc={['战队名称,可在url中找到。例如:https://liquipedia.net/counterstrike/G2_Esports']}/>

## Maxjia News {#maxjia-news}

### Dota 2 {#maxjia-news-dota-2}

<Route author="dearrrfish" example="/maxnews/dota2" path="maxnews/dota2" />
<Route author="dearrrfish" example="/maxnews/dota2" path="/maxnews/dota2" />

## Minecraft {#minecraft}

Expand Down

0 comments on commit 96e73ff

Please sign in to comment.