espn-ff
Version:
ESPN Fantasy Football Scraper
53 lines • 2.25 kB
JavaScript
;
var cheerio = require('cheerio');
var _ = require('lodash');
var OwnersParser = (function () {
function OwnersParser() {
this.name = 'scoreboard';
}
OwnersParser.prototype.parse = function (context) {
var _this = this;
var result = [];
var matchups = context.selector('table.matchup');
if (matchups.length == 0) {
return null;
}
matchups.each(function (index, matchup) {
result.push(_this.parseMatchup(matchup));
});
return result;
};
OwnersParser.prototype.parseMatchup = function (element) {
// Away team @ index 1
var away = cheerio('tr:nth-of-type(1)', element)[0];
var home = cheerio('tr:nth-of-type(2)', element)[0];
var details = cheerio('.scoringDetails', element)[0];
var result = {
home_team: this.parseMatchupTeam(home, details),
away_team: this.parseMatchupTeam(away, details)
};
return result;
};
OwnersParser.prototype.parseMatchupTeam = function (element, details) {
// Extract the team id from the element
var idString = element.attribs.id;
var teamId = parseInt(idString.split('_')[1]);
return {
id: teamId,
name: cheerio('.team > .name > a', element).text(),
short_name: _.trim(cheerio('.team > .name > .abbrev', element).text(), '()'),
division: null,
record: _.trim(cheerio('.record', element).text(), '()'),
owner_name: cheerio('.owners', element).text(),
current_points: parseFloat(cheerio('.score', element).text()),
in_play: parseInt(cheerio("#team_ip_" + teamId, details).text()),
yet_to_play: parseInt(cheerio("#team_ytp_" + teamId, details).text()),
mins_left: parseInt(cheerio("#team_pmr_" + teamId, details).text()),
projected_points: parseFloat(cheerio("#team_liveproj_" + teamId, details).text()),
};
};
return OwnersParser;
}());
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = OwnersParser;
//# sourceMappingURL=Scoreboard.js.map