UNPKG

espn-ff

Version:
96 lines 4 kB
"use strict"; var cheerio = require('cheerio'); var ClubhouseParser = (function () { function ClubhouseParser() { this.name = 'clubhouse'; } ClubhouseParser.prototype.parse = function (context) { var _this = this; var rosterTable = context.selector('.playerTableTable'); if (rosterTable.length === 0) { return null; } var roster = { starters: [], bench: [], week: 0 }; var activeSlotSet = null; rosterTable.children('tr').each(function (index, element) { // Look for pncPlayerRow for players and tableHead for start vs bench seperation if (!element.attribs || !element.attribs['class']) { return; } // Header if (element.attribs['class'].indexOf('tableHead') >= 0) { if (activeSlotSet == null) { // Pull out the week number var weekText = cheerio('th:nth-of-type(2)', element).text(); roster.week = parseInt(weekText.split(' ')[1]); activeSlotSet = roster.starters; } else { activeSlotSet = roster.bench; } return; } // Player if (element.attribs['class'].indexOf('pncPlayerRow') >= 0) { var player = _this.parseRosterSlot(element); activeSlotSet.push(player); } }); return roster; }; ClubhouseParser.prototype.parseRosterSlot = function (element) { var rosterSlot = { slot: cheerio('.playerSlot', element).text(), player: this.parsePlayer(element), gameStart: cheerio('.gameStatusDiv', element).text(), matchup: this.parsePlayerMatchup(element), opponent: cheerio('td:nth-child(5)', element).text() // Slot + player + action + seperator }; return rosterSlot; }; ClubhouseParser.prototype.parsePlayer = function (element) { var playerName = cheerio('.playertablePlayerName', element); var playerText = playerName.text(); var team = 'N/A'; if (playerText.indexOf(',') > 0) { // Human player var parts = playerText.split(',').map(function (p) { return p.trim(); }); playerText = parts[0]; team = parts[1].split(' ')[0]; } return { name: playerText, team: team, id: 1, season_statistics: { player_rank: parseInt(cheerio('td:nth-of-type(8)', element).text()), total_points: parseFloat(cheerio('td:nth-of-type(9)', element).text()), average_points: parseFloat(cheerio('td:nth-of-type(10)', element).text()), last_game_points: parseFloat(cheerio('td:nth-of-type(11)', element).text()) } }; }; ClubhouseParser.prototype.parsePlayerMatchup = function (element) { var oppenent_rank = cheerio('td:nth-of-type(14)', element).text(); // Empty slot if (oppenent_rank == '--') { return null; } oppenent_rank = parseInt(/([0-9]+)/.exec(oppenent_rank)[0]); return { projected_or_current_points: parseFloat(cheerio('td:nth-of-type(13)', element).text()), opponent_rank: 1, percent_start: parseFloat(cheerio('td:nth-of-type(15)', element).text()), percent_own: parseFloat(cheerio('td:nth-of-type(16)', element).text()), percent_own_delta: parseFloat(cheerio('td:nth-of-type(17)', element).text()) }; }; return ClubhouseParser; }()); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = ClubhouseParser; //# sourceMappingURL=Clubhouse.js.map