feat(route): add counterstrike match results from liquipedia (#13855)

* 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

---------
This commit is contained in:
Wang Yuhan 2023-11-23 21:22:37 +08:00 committed by GitHub
parent 7eb8cbc7fb
commit 96e73ff36e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 134 additions and 54 deletions

View File

@ -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'));

View File

@ -1,50 +0,0 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
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 &&
list
.map((index, 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(5) > a').text();
const date_time = new Date(date + ' ' + time).toUTCString();
const score = item.find('td:nth-child(6)').text();
const vs_team = item.find('td:nth-child(7) > span > span.team-template-text > a').text();
return {
title: `[${message}] ${score} ${vs_team}`,
description: `At ${tournament}, ${team} ${score} ${vs_team}`,
pubDate: date_time,
link: url,
guid: url + date_time,
};
})
.get(),
};
};

View File

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

View File

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

View File

@ -0,0 +1,4 @@
module.exports = {
'/counterstrike/matches/:team': ['CookiePieWw'],
'/dota2/matches/:id': ['wzekin'],
};

View File

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

View File

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

View File

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