diff --git a/db/top_statistics.json b/db/top_statistics.json index af7225d7..1f8da3ac 100644 --- a/db/top_statistics.json +++ b/db/top_statistics.json @@ -89,8 +89,8 @@ "rank": 1, "team": "Saiyans FC", "image": "https://kingsleague.dev/teams/logos/saiyans-fc.svg", - "playerImage": "saiyans-fc-feliu.webp", - "teamId": "saiyans-fc" + "teamId": "saiyans-fc", + "playerImage": "saiyans-fc-20.webp" }, { "playerName": "Jacobo", @@ -99,7 +99,6 @@ "rank": 2, "team": "El Barrio", "image": "https://kingsleague.dev/teams/logos/el-barrio.svg", - "playerImage": "el-barrio-jacobo.webp", "teamId": "el-barrio" }, { @@ -109,7 +108,6 @@ "rank": 3, "team": "Los Troncos FC", "image": "https://kingsleague.dev/teams/logos/los-troncos.svg", - "playerImage": "placeholder.png", "teamId": "los-troncos-fc" }, { @@ -119,7 +117,6 @@ "rank": 4, "team": "Ultimate Móstoles", "image": "https://kingsleague.dev/teams/logos/ultimate-mostoles.svg", - "playerImage": "ultimate-mostoles-juanma-glez.webp", "teamId": "ultimate-mostoles" }, { @@ -129,7 +126,6 @@ "rank": 5, "team": "Kunisports", "image": "https://kingsleague.dev/teams/logos/kunisports.svg", - "playerImage": "kunisports-vctor.webp", "teamId": "kunisports" } ], @@ -141,8 +137,8 @@ "goals": 3, "team": "Saiyans FC", "image": "https://kingsleague.dev/teams/logos/saiyans-fc.svg", - "playerImage": "saiyans-fc-r-carbo.webp", - "teamId": "saiyans-fc" + "teamId": "saiyans-fc", + "playerImage": "saiyans-fc-11.webp" }, { "rank": 2, @@ -151,7 +147,6 @@ "goals": 3, "team": "Ultimate Móstoles", "image": "https://kingsleague.dev/teams/logos/ultimate-mostoles.svg", - "playerImage": "ultimate-mostoles-juanma-glez.webp", "teamId": "ultimate-mostoles" }, { @@ -161,7 +156,6 @@ "goals": 2, "team": "El Barrio", "image": "https://kingsleague.dev/teams/logos/el-barrio.svg", - "playerImage": "el-barrio-jacobo.webp", "teamId": "el-barrio" }, { @@ -171,7 +165,6 @@ "goals": 2, "team": "Los Troncos FC", "image": "https://kingsleague.dev/teams/logos/los-troncos.svg", - "playerImage": "los-troncos-fc-s-sanchez-drago.webp", "teamId": "los-troncos-fc" }, { @@ -181,7 +174,6 @@ "goals": 2, "team": "Los Troncos FC", "image": "https://kingsleague.dev/teams/logos/los-troncos.svg", - "playerImage": "placeholder.png", "teamId": "los-troncos-fc" } ], @@ -193,8 +185,8 @@ "rank": 1, "team": "Los Troncos FC", "image": "https://kingsleague.dev/teams/logos/los-troncos.svg", - "playerImage": "placeholder.png", - "teamId": "los-troncos-fc" + "teamId": "los-troncos-fc", + "playerImage": "los-troncos-fc-23.webp" }, { "playerName": "A. Bueno", @@ -203,7 +195,6 @@ "rank": 2, "team": "1K FC", "image": "https://kingsleague.dev/teams/logos/1k.svg", - "playerImage": "placeholder.png", "teamId": "1k" }, { @@ -213,7 +204,6 @@ "rank": 3, "team": "Saiyans FC", "image": "https://kingsleague.dev/teams/logos/saiyans-fc.svg", - "playerImage": "saiyans-fc-gio-ferinu.webp", "teamId": "saiyans-fc" }, { @@ -223,7 +213,6 @@ "rank": 4, "team": "Saiyans FC", "image": "https://kingsleague.dev/teams/logos/saiyans-fc.svg", - "playerImage": "saiyans-fc-feliu.webp", "teamId": "saiyans-fc" }, { @@ -233,7 +222,6 @@ "rank": 5, "team": "Saiyans FC", "image": "https://kingsleague.dev/teams/logos/saiyans-fc.svg", - "playerImage": "saiyans-fc-david-alba.webp", "teamId": "saiyans-fc" } ] diff --git a/scraping/top_statistics.js b/scraping/top_statistics.js index e9885d0f..f5ac1e5d 100644 --- a/scraping/top_statistics.js +++ b/scraping/top_statistics.js @@ -12,7 +12,29 @@ const [leaderboardDB, mvpDB, topScorersDB, topAssistsDB] = await Promise.all([ readDBFile('players_twelve') ]) -export function getTopStatistics() { +const keys = [ + { + category: 'mvp' + }, + { + category: 'topScorers' + }, + { + category: 'topAssists' + } +] + +export function getTopStatistics($) { + const extractIdFromUrl = (url) => url.split('/').at(-1).split('.').at(0) + + const $rows = $('.uk-card-media-right.uk-cover-container>img.el-image:not(.uk-invisible)') + + $rows.each((idx, el) => { + const $el = $(el) + const id = extractIdFromUrl($el.attr('src')) + keys[idx].id = id + }) + const leaderboard = leaderboardDB.slice(0, 5).map((data) => { const { team, ...rest } = data const { id, name, image, coach, shortName } = team @@ -32,31 +54,33 @@ export function getTopStatistics() { const topScorers = getLimitFrom(topScorersDB).map(extractMoreData) const topAssists = getLimitFrom(topAssistsDB).map(extractMoreData) - return { leaderboard, mvp, topScorers, topAssists } + return { + leaderboard, + mvp: addImageToFirstPlayer(mvp, 'mvp'), + topScorers: addImageToFirstPlayer(topScorers, 'topScorers'), + topAssists: addImageToFirstPlayer(topAssists, 'topAssists') + } } function extractMoreData(player) { const { team: teamName } = player const team = TEAMS.find((team) => team.name === teamName) - const { players, id: teamId } = team - - const playerImage = findPlayerImage({ playerName: player.playerName, players }) + const { id: teamId } = team return { ...player, - playerImage, teamId } } -function findPlayerImage({ playerName, players }) { - console.log(playerName) - - const player = players.find((player) => player.name === playerName) - const playerImage = player?.image ? `${player.image}` : 'placeholder.png' - - // buscar player 12 - - return playerImage +function addImageToFirstPlayer(array, category) { + return [ + ...array.slice(0, 1).map((player) => { + const id = keys.find((key) => key.category === category).id + const playerImage = `${player.teamId}-${id}.webp` + return { ...player, playerImage } + }), + ...array.slice(1) + ] } diff --git a/scraping/utils.js b/scraping/utils.js index e7ef1d24..60d13188 100644 --- a/scraping/utils.js +++ b/scraping/utils.js @@ -36,6 +36,7 @@ export const SCRAPINGS = { scraper: getSchedule }, top_statistics: { + url: 'https://kingsleague.pro/estadisticas/', scraper: getTopStatistics } // coaches: {