-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 ---------
- Loading branch information
1 parent
7eb8cbc
commit 96e73ff
Showing
8 changed files
with
134 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
}), | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
'/counterstrike/matches/:team': ['CookiePieWw'], | ||
'/dota2/matches/:id': ['wzekin'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}, | ||
], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters