flea-killer
Advanced tools
Comparing version 0.2.1 to 0.2.2
// League scraper | ||
var request = require('request'), | ||
cheerio = require('cheerio'), | ||
validate = require('./validate'); | ||
cheerio = require('cheerio'), | ||
validate = require('./validate'); | ||
@@ -33,4 +33,4 @@ // Fetch league information | ||
return $(this).find(children).filter(function() { | ||
return $(this).text().trim() === search; | ||
}).next().text().trim(); | ||
return $(this).text().trim() === search; | ||
}).next().text().trim(); | ||
}; | ||
@@ -45,3 +45,3 @@ | ||
slots: { | ||
total: $('.table-group .user-name').length + $('.table-group a.btn-success').length, | ||
total: $('.league-name').length, | ||
available: $('.table-group a.btn-success').length, | ||
@@ -59,36 +59,32 @@ taken: $('.table-group .user-name').length | ||
// cheerio bug is forces it unable to find tbody for some odd reason | ||
// for (var i = 0, l = $('.table-group .user-name').length; i < l; i++) { | ||
$(`.table-group > tr`).each(function() { | ||
// console.log(i, l); | ||
// Only take real teams | ||
if ($(this).find('td:first-child .league-name').length > 0) { | ||
var team = { | ||
name: $(this).find('td:first-child .league-name').text(), | ||
rank: $(this).find('td:last-child').text(), | ||
points: $(this).find('td:last-child').prev().text(), | ||
link: 'https://fleaflicker.com' + $(this).find('td.left .league-name a').attr('href'), | ||
id: $(this).find('td:first-child .league-name a').attr('href').match(/\/teams\/(\d{5,7})/)[1], | ||
owner: { | ||
name: $(this).find('.user-name').text(), | ||
link: 'https://fleaflicker.com' + $(this).find('.user-name').attr('href') | ||
}, | ||
stats: {} | ||
}; | ||
var row = $(this); | ||
// Push on the stats for the entire team | ||
league.stats.forEach(function(stat, index) { | ||
team.stats[stat] = { | ||
points: parseFloat(row.find('td:nth-child(' + (index + 4) + ')' + ' .text-muted').text()), | ||
value: parseFloat(row.find('td:nth-child(' + (index + 4) + ')' + ' .nowrap').text().replace(/,/g, '')) | ||
} | ||
}); | ||
league.teams.push(team); | ||
} | ||
}); | ||
// } | ||
$('#body-center-main tr').each(function() { | ||
// Only take real teams | ||
if ($(this).find('td .league-name').length > 0) { | ||
var team = { | ||
name: $(this).find('td .league-name').text(), | ||
rank: $(this).find('td:nth-child(19)').text(), | ||
points: $(this).find('td:nth-child(16)').text(), | ||
link: 'https://fleaflicker.com' + $(this).find('td.left .league-name a').attr('href'), | ||
id: $(this).find('td .league-name a').attr('href').match(/\/teams\/(\d{5,7})/)[1], | ||
owner: { | ||
name: $(this).find('.user-name').text(), | ||
link: 'https://fleaflicker.com' + $(this).find('.user-name').attr('href') | ||
}, | ||
stats: {} | ||
}; | ||
var row = $(this); | ||
// Push on the stats for the entire team | ||
league.stats.forEach(function(stat, index) { | ||
team.stats[stat] = { | ||
points: parseFloat(row.find('td:nth-child(' + (index + 4) + ')' + ' .text-muted').text()), | ||
value: parseFloat(row.find('td:nth-child(' + (index + 4) + ')' + ' .nowrap').text().replace(/,/g, '')) | ||
} | ||
}); | ||
league.teams.push(team); | ||
} | ||
}); | ||
return callback(null, league); | ||
}); | ||
} |
@@ -46,16 +46,13 @@ // Team scraper | ||
}; | ||
// cheerio bug is forces it unable to find tbody for some odd reason | ||
for (var i = 0; i < $('#body-center-main .player').length - 1; i++) { | ||
$('#row_0_0_' + i).each(function() { | ||
// Only take real teams | ||
if ($(this).find('td:first-child .player').length > 0) { | ||
var player = { | ||
name: $(this).find('td .player').text(), | ||
totalPoints: parseFloat($(this).find('td .fp').first().text()), | ||
avgPoints: parseFloat($(this).find('td .fp').eq(1).text()) | ||
}; | ||
team.players.push(player); | ||
} | ||
}); | ||
} | ||
$('#body-center-main td').each(function() { | ||
// Only take real teams | ||
if ($(this).find('td:first-child .player').length > 0) { | ||
var player = { | ||
name: $(this).find('td .player').text(), | ||
totalPoints: parseFloat($(this).find('td .fp').first().text()), | ||
avgPoints: parseFloat($(this).find('td .fp').eq(1).text()) | ||
}; | ||
team.players.push(player); | ||
} | ||
}); | ||
return callback(null, team); | ||
@@ -62,0 +59,0 @@ }); |
{ | ||
"name": "flea-killer", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"description": "Fleaflicker Baseball API", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -56,17 +56,17 @@ var expect = require('chai').expect, | ||
it('should grab the correct league information', function(done){ | ||
league.get('http://www.fleaflicker.com/mlb/leagues/20119?season=2018', function(err, league){ | ||
expect(league.name).to.equal('The Sultans of Stats 2018'); | ||
expect(league.commish).to.equal('SultansOfStats'); | ||
league.get('http://www.fleaflicker.com/mlb/leagues/17027?season=2016', function(err, league){ | ||
expect(league.name).to.equal('Reddit-2016-10'); | ||
expect(league.commish).to.equal('NextLevelFntsy'); | ||
expect(league.type).to.equal('Roto'); | ||
expect(league.slots.total).to.equal(16); | ||
expect(league.slots.total).to.equal(12); | ||
// Cant test avail/taken as those slots change and I dont want to mock it | ||
expect(league.id).to.equal(20119); | ||
expect(league.id).to.equal(17027); | ||
// Cant test individual stats that well | ||
expect(league.teams.length).to.equal(16); | ||
expect(league.teams[0].stats.HR.points).to.equal(15); | ||
expect(league.teams[0].stats.HR.value).to.equal(44); | ||
expect(league.teams[0].stats.ERA.value).to.equal(3.51); | ||
expect(league.teams[0].stats.ERA.points).to.equal(10); | ||
expect(league.teams[0].stats.QS.value).to.equal(15); | ||
expect(league.teams[0].stats.QS.points).to.equal(6.5); | ||
expect(league.teams[0].name).to.equal('Mucho Machado Machismo'); | ||
expect(league.teams[0].stats.HR.points).to.equal(12); | ||
expect(league.teams[0].stats.HR.value).to.equal(324); | ||
expect(league.teams[0].stats.ERA.value).to.equal(4.06); | ||
expect(league.teams[0].stats.ERA.points).to.equal(2); | ||
expect(league.teams[0].stats.QS.value).to.equal(84); | ||
expect(league.teams[0].stats.QS.points).to.equal(5); | ||
done(); | ||
@@ -73,0 +73,0 @@ }); |
22316
439