From a73d0418bfd83dd8ceacae7bb5446191076e2727 Mon Sep 17 00:00:00 2001 From: DIYgod Date: Fri, 30 Aug 2019 00:07:54 +0800 Subject: [PATCH] feat: psn trophy --- docs/game.md | 8 +++- lib/router.js | 1 + lib/routes/ps/trophy.js | 93 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 100 insertions(+), 2 deletions(-) create mode 100644 lib/routes/ps/trophy.js diff --git a/docs/game.md b/docs/game.md index 90831878d..709e81707 100644 --- a/docs/game.md +++ b/docs/game.md @@ -90,9 +90,9 @@ pageClass: routes -## PlayStation Store +## PlayStation -### 游戏列表 +### PlayStation Store 游戏列表 @@ -100,6 +100,10 @@ pageClass: routes +### PlayStation Network 用户奖杯 + + + ## psnine ### 首页-白金攻略/游戏开箱 diff --git a/lib/router.js b/lib/router.js index c024805bc..b3d477bc5 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1268,6 +1268,7 @@ router.get('/mlhang', require('./routes/mlhang/latest')); // PlayStation Store router.get('/ps/list/:gridName', require('./routes/ps/list')); +router.get('/ps/trophy/:id', require('./routes/ps/trophy')); // Nintendo router.get('/nintendo/eshop/jp', require('./routes/nintendo/eshop_jp')); diff --git a/lib/routes/ps/trophy.js b/lib/routes/ps/trophy.js new file mode 100644 index 000000000..c7116c9a3 --- /dev/null +++ b/lib/routes/ps/trophy.js @@ -0,0 +1,93 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const id = ctx.params.id; + + const response = await got({ + method: 'get', + url: `https://psnprofiles.com/${id}?order=last-trophy`, + }); + + const $ = cheerio.load(response.data); + const list = $('.zebra tr') + .filter(function() { + return ( + $(this) + .find('.progress-bar span') + .text() !== '0%' + ); + }) + .map((i, e) => + $(e) + .find('.title') + .attr('href') + ) + .get() + .slice(0, 3); + + const items = await Promise.all( + list.map(async (item) => { + const link = 'https://psnprofiles.com' + item + '?order=date&trophies=earned&lang=zh-cn'; + + const response = await got({ + method: 'get', + url: link, + }); + + const $ = cheerio.load(response.data); + + const list = $('.zebra tr.completed'); + const items = list + .map((i, item) => { + item = $(item); + return { + title: + item.find('.title').text() + + ' - ' + + $('.page h3') + .eq(0) + .text() + .trim(), + description: `
${item + .find('.title') + .parent() + .contents() + .filter(function() { + return this.nodeType === 3; + }) + .text() + .trim()}
珍贵度:${item.find('.hover-show .typo-top').text()}`, + link: 'https://psnprofiles.com' + item.find('.title').attr('href'), + pubDate: new Date( + +new Date( + item + .find('.typo-top-date nobr') + .contents() + .filter(function() { + return this.nodeType === 3; + }) + .text() + + ' ' + + item.find('.typo-bottom-date').text() + ) + + 8 * 60 * 60 * 1000 + ).toUTCString(), + }; + }) + .get(); + + return Promise.resolve(items); + }) + ); + let result = []; + items.forEach((item) => { + result = result.concat(item); + }); + + ctx.state.data = { + title: `${id} 的 PSN 奖杯`, + link: `https://psnprofiles.com/${id}/log`, + item: result, + }; +};