Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing refactors #19

Merged
merged 3 commits into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
.vscode
examples
examples
mochawesome-report
1 change: 1 addition & 0 deletions app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports.nba = require('./services/nba.service');
module.exports.ncaa = require('./services/ncaa.service');
module.exports.nfl = require('./services/nfl.service');
module.exports.nhl = require('./services/nhl.service');
module.exports.tnns = require('./services/tnns.service');
module.exports.wbb = require('./services/wbb.service');
module.exports.wnba = require('./services/wnba.service');

119 changes: 62 additions & 57 deletions app/services/cfb.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = {
* @example
* const result = await sdv.cfb.getPlayByPlay(401256194);
*/
getPlayByPlay: async function(id) {
getPlayByPlay: async function (id) {
const baseUrl = 'http://cdn.espn.com/core/college-football/playbyplay';
const params = {
gameId: id,
Expand Down Expand Up @@ -51,7 +51,7 @@ module.exports = {
* @example
* const result = await sdv.cfb.getBoxScore(401256194);
*/
getBoxScore: async function (id){
getBoxScore: async function (id) {
const baseUrl = 'http://cdn.espn.com/core/college-football/boxscore';
const params = {
gameId: id,
Expand Down Expand Up @@ -80,7 +80,7 @@ module.exports = {
* @example
* const result = await sdv.cfb.getSummary(401256194);
*/
getSummary: async function(id) {
getSummary: async function (id) {
const baseUrl = 'http://site.api.espn.com/apis/site/v2/sports/football/college-football/summary';
const params = {
event: id
Expand Down Expand Up @@ -117,7 +117,7 @@ module.exports = {
* @example
* const result = await sdv.cfb.getPicks(401256194);
*/
getPicks: async function(id) {
getPicks: async function (id) {
const baseUrl = 'http://site.api.espn.com/apis/site/v2/sports/football/college-football/summary';
const params = {
event: id
Expand Down Expand Up @@ -157,7 +157,7 @@ module.exports = {
* @example
* const result = await sdv.cfb.getPlayerRankings({year: 2016});
*/
getPlayerRankings: async function({
getPlayerRankings: async function ({
year,
page = 1,
group = "HighSchool",
Expand All @@ -174,7 +174,7 @@ module.exports = {

const res = await axios.get(baseUrl, {
headers: {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36'
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36'
},
params
});
Expand All @@ -192,15 +192,15 @@ module.exports = {
let metrics = html.find('.metrics').text().split('/');

let player = {
ranking: rank,
name: html.find('.rankings-page__name-link').text().trim(),
highSchool: html.find('span.meta').text().trim(),
position: html.find('.position').text().trim(),
height: metrics[0],
weight: metrics[1],
stars: html.find('.rankings-page__star-and-score > .yellow').length,
rating: html.find('.score').text().trim().trim(),
college: html.find('.img-link > img').attr('title') || 'uncommitted'
ranking: rank,
name: html.find('.rankings-page__name-link').text().trim(),
highSchool: html.find('span.meta').text().trim(),
position: html.find('.position').text().trim(),
height: metrics[0],
weight: metrics[1],
stars: html.find('.rankings-page__star-and-score > .yellow').length,
rating: html.find('.score').text().trim().trim(),
college: html.find('.img-link > img').attr('title') || 'uncommitted'
};

players.push(player);
Expand All @@ -220,15 +220,15 @@ module.exports = {
* @example
* const result = await sdv.cfb.getSchoolRankings({year: 2016});
*/
getSchoolRankings: async function(year, page = 1) {
getSchoolRankings: async function (year, page = 1) {
const baseUrl = `http://247sports.com/Season/${year}-Football/CompositeTeamRankings`;

const res = await axios.get(baseUrl, {
headers: {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36'
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36'
},
params: {
Page: page
Page: page
}
});

Expand All @@ -239,14 +239,14 @@ module.exports = {
let html = $(this);

let school = {
rank: html.find('.rank-column .primary').text().trim(),
school: html.find('.rankings-page__name-link').text().trim(),
totalCommits: html.find('.total a').text().trim(),
fiveStars: $(html.find('ul.star-commits-list > li > div')[0]).text().replace('5: ', '').trim(),
fourStars: $(html.find('ul.star-commits-list > li > div')[1]).text().replace('4: ', '').trim(),
threeStars: $(html.find('ul.star-commits-list > li > div')[2]).text().replace('3: ', '').trim(),
averageRating: html.find('.avg').text().trim(),
points: html.find('.number').text().trim()
rank: html.find('.rank-column .primary').text().trim(),
school: html.find('.rankings-page__name-link').text().trim(),
totalCommits: html.find('.total a').text().trim(),
fiveStars: $(html.find('ul.star-commits-list > li > div')[0]).text().replace('5: ', '').trim(),
fourStars: $(html.find('ul.star-commits-list > li > div')[1]).text().replace('4: ', '').trim(),
threeStars: $(html.find('ul.star-commits-list > li > div')[2]).text().replace('3: ', '').trim(),
averageRating: html.find('.avg').text().trim(),
points: html.find('.number').text().trim()
};

schools.push(school);
Expand All @@ -265,12 +265,12 @@ module.exports = {
* @example
* const result = await sdv.cfb.getSchoolCommits({school: 'Florida State', year: 2021});
*/
getSchoolCommits: async function(school, year){
getSchoolCommits: async function (school, year) {
const baseUrl = `http://${school}.247sports.com/Season/${year}-Football/Commits`;

const res = await axios.get(baseUrl, {
headers: {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36'
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36'
}
});

Expand All @@ -284,16 +284,16 @@ module.exports = {
let metrics = html.find('.metrics').text().split('/');

let player = {
name: html.find('.ri-page__name-link').text().trim(),
highSchool: html.find('span.meta').text().trim(),
position: $(html.find('.position')).text().trim(),
height: metrics[0],
weight: metrics[1],
stars: html.find('.ri-page__star-and-score .yellow').length,
rating: html.find('span.score').clone().children().remove().end().text().trim(),
nationalRank: html.find('.natrank').first().text().trim(),
stateRank: html.find('.sttrank').first().text().trim(),
positionRank: html.find('.posrank').first().text().trim()
name: html.find('.ri-page__name-link').text().trim(),
highSchool: html.find('span.meta').text().trim(),
position: $(html.find('.position')).text().trim(),
height: metrics[0],
weight: metrics[1],
stars: html.find('.ri-page__star-and-score .yellow').length,
rating: html.find('span.score').clone().children().remove().end().text().trim(),
nationalRank: html.find('.natrank').first().text().trim(),
stateRank: html.find('.sttrank').first().text().trim(),
positionRank: html.find('.posrank').first().text().trim()
};

players.push(player);
Expand All @@ -317,23 +317,22 @@ module.exports = {
* @example
* const result = await sdv.cfb.getRankings(year = 2020, week = 4)
*/
getRankings: async function({year = null, week = null}) {
const baseUrl = 'http://cdn.espn.com/core/college-football/rankings?';
const qs = {};
getRankings: async function ({ year, week }) {
const baseUrl = 'http://cdn.espn.com/core/college-football/rankings';
const params = {};

if (year) {
qs.year = year;
params.year = year;
}

if (week) {
qs.week = week;
params.week = week;
}

const res = await axios.get(baseUrl, {
params: qs
params
});

return res.content.data;
return res.data;
},
/**
* Gets the College Football schedule data for a specified date if available.
Expand All @@ -349,8 +348,8 @@ module.exports = {
* @example
* const result = await sdv.cfb.getSchedule(year = 2019, month = 11, day = 16, group=80)
*/
getSchedule: async function ({year = null, month = null, day = null, groups = 80, seasontype = 2}){
const baseUrl = `http://cdn.espn.com/core/college-football/schedule?dates=${year}${parseInt(month) <= 9 ? "0" + parseInt(month) : parseInt(month)}${parseInt(day) <= 9 ? "0" + parseInt(day) : parseInt(day)}`;
getSchedule: async function ({ year, month, day, groups = 80, seasontype = 2 }) {
const baseUrl = `http://cdn.espn.com/core/college-football/schedule`;
const params = {
groups: groups,
seasontype: seasontype,
Expand All @@ -359,6 +358,9 @@ module.exports = {
device: 'desktop',
userab: 18
};
if (year && month && day) {
params.dates = `${year}${parseInt(month) <= 9 ? "0" + parseInt(month) : parseInt(month)}${parseInt(day) <= 9 ? "0" + parseInt(day) : parseInt(day)}`;
}

const res = await axios.get(baseUrl, {
params
Expand All @@ -382,14 +384,17 @@ module.exports = {
* year = 2019, month = 11, day = 16, group=80
* )
*/
getScoreboard: async function({year = null, month = null, day = null, groups = 80, seasontype = 2, limit = 300}) {
getScoreboard: async function ({ year, month, day, groups = 80, seasontype = 2, limit = 300 }) {

const baseUrl = `http://site.api.espn.com/apis/site/v2/sports/football/college-football/scoreboard?dates=${year}${parseInt(month) <= 9 ? "0" + parseInt(month) : parseInt(month)}${parseInt(day) <= 9 ? "0" + parseInt(day) : parseInt(day)}`;
const baseUrl = `http://site.api.espn.com/apis/site/v2/sports/football/college-football/scoreboard`;
const params = {
groups: groups,
seasontype,
limit
};
if (year && month && day) {
params.dates = `${year}${parseInt(month) <= 9 ? "0" + parseInt(month) : parseInt(month)}${parseInt(day) <= 9 ? "0" + parseInt(day) : parseInt(day)}`;
}

const res = await axios.get(baseUrl, {
params
Expand All @@ -409,7 +414,7 @@ module.exports = {
* const yr = 2021;
* const result = await sdv.cfb.getConferences(year = yr, group = 80);
*/
getConferences: async function ({year = new Date().getFullYear(), group = 80}){
getConferences: async function ({ year = new Date().getFullYear(), group = 80 }) {
const baseUrl = 'http://site.api.espn.com/apis/site/v2/sports/football/college-football/scoreboard/conferences';

const params = {
Expand All @@ -433,7 +438,7 @@ module.exports = {
* const yr = 2020;
* const result = await sdv.cfb.getStandings(year = yr);
*/
getStandings: async function ({year = new Date().getFullYear(), group = 80}){
getStandings: async function ({ year = new Date().getFullYear(), group = 80 }) {
const baseUrl = `https://site.web.api.espn.com/apis/v2/sports/football/college-football/standings`;
const params = {
region: 'us',
Expand All @@ -443,9 +448,9 @@ module.exports = {
group: group,
type: 0,
level: 1,
sort: 'winpercent:desc,leaguewinpercent:desc,vsconf_winpercent:desc,'+
'vsconf_gamesbehind:asc,vsconf_playoffseed:asc,wins:desc,'+
'losses:desc,playoffseed:asc,alpha:asc'
sort: 'winpercent:desc,leaguewinpercent:desc,vsconf_winpercent:desc,' +
'vsconf_gamesbehind:asc,vsconf_playoffseed:asc,wins:desc,' +
'losses:desc,playoffseed:asc,alpha:asc'
};
const res = await axios.get(baseUrl, {
params
Expand All @@ -462,7 +467,7 @@ module.exports = {
* @example
* const result = await sdv.cfb.getTeamList(group=80);
*/
getTeamList: async function ({group = 80}) {
getTeamList: async function ({ group = 80 }) {
const baseUrl = 'http://site.api.espn.com/apis/site/v2/sports/football/college-football/teams';
const params = {
group,
Expand All @@ -486,7 +491,7 @@ module.exports = {
* const teamId = 52;
* const result = await sdv.cfb.getTeamInfo(teamId);
*/
getTeamInfo: async function(id) {
getTeamInfo: async function (id) {
const baseUrl = `http://site.api.espn.com/apis/site/v2/sports/football/college-football/teams/${id}`;

const res = await axios.get(baseUrl);
Expand Down
Loading