From 10d0e0b2e9b9defe6b8384970bd1e9ba08044fac Mon Sep 17 00:00:00 2001 From: zekin Date: Fri, 30 Oct 2020 17:48:56 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20Dota2=20=E6=88=98=E9=98=9F=E6=9C=80?= =?UTF-8?q?=E6=96=B0=E6=AF=94=E8=B5=9B=E7=BB=93=E6=9E=9C=20(#6005)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/game.md | 6 ++++ lib/router.js | 3 ++ lib/routes/liquipedia/dota2_matches.js | 50 ++++++++++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 lib/routes/liquipedia/dota2_matches.js diff --git a/docs/game.md b/docs/game.md index 4079061f90..c08459f7c5 100644 --- a/docs/game.md +++ b/docs/game.md @@ -112,6 +112,12 @@ pageClass: routes +## Liquipedia + +### Dota2 战队最近比赛结果 + + + ## Maxjia News ### Dota 2 diff --git a/lib/router.js b/lib/router.js index 09d3010330..0775b23551 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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')); diff --git a/lib/routes/liquipedia/dota2_matches.js b/lib/routes/liquipedia/dota2_matches.js new file mode 100644 index 0000000000..e459f6b405 --- /dev/null +++ b/lib/routes/liquipedia/dota2_matches.js @@ -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(), + }; +};