feat: Dota2 战队最新比赛结果 (#6005)

This commit is contained in:
zekin
2020-10-30 09:48:56 +00:00
committed by GitHub
parent 4e31222c13
commit 10d0e0b2e9
3 changed files with 59 additions and 0 deletions
+6
View File
@@ -112,6 +112,12 @@ pageClass: routes
<Route author="GensouSakuya kt286" example="/indienova/article" path="indienova/:type" :paramsDesc="['类型: `article` 文章,`development` 开发']"/>
## Liquipedia
### Dota2 战队最近比赛结果
<Route author="wzekin" example="/liquipedia/dota2/matches/Team_Aster" path="liquipedia/dota2/matches/:id" :paramsDesc="['战队名称,可在url中找到。例如:https://liquipedia.net/dota2/Team_Aster']"/>
## Maxjia News
### Dota 2
+3
View File
@@ -3419,6 +3419,9 @@ router.get('/sagawa/:id', require('./routes/sagawa/index'));
// QNAP
router.get('/qnap/release-notes/:id', require('./routes/qnap/release-notes'));
// Liquipedia
router.get('/liquipedia/dota2/matches/:id', require('./routes/liquipedia/dota2_matches.js'));
// 哈尔滨市科技局
router.get('/gov/harbin/kjj', require('./routes/gov/harbin/kjj'));
+50
View File
@@ -0,0 +1,50 @@
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: 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(),
};
};