Code Monkey home page Code Monkey logo

sportsdataverse / sportsdataverse-js Goto Github PK

View Code? Open in Web Editor NEW
47.0 9.0 12.0 16.05 MB

Retrieves sports data from a popular sports website as well as from the NCAA website, with support for NBA, WNBA, NFL, NHL, College Football and mens and womens college basketball,

Home Page: https://js.sportsdataverse.org

JavaScript 96.76% Handlebars 3.24%
nodejs node node-js hockey soccer volleyball tennis college-football college-basketball nba nfl nhl espn 247sports basketball-women basketball-men cfb wnba sportsdataverse javascript

sportsdataverse-js's People

Contributors

baclap avatar dependabot[bot] avatar saiemgilani avatar unmonk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sportsdataverse-js's Issues

Issue pulling NCAAB Scores

Hi, this is a great package and really hoping to use it to gather ncaa basketball scores for an app. I am running into an issue, and I cannot seem to resolve it. Here is my code

const sdv = require("sportsdataverse");

async function getScores() {
  try {
    const inputs = {
      year: 2021,
      month: 02,
      day: 15,
    };
    const result = await sdv.cbbScoreboard.getScoreboard(inputs);
    console.log(result);
  } catch (e) {
    console.log(e);
  }
}

getScores();

When i run node index.js I am getting an error - output below. Cant seem to fix this, was wondering if you can help dissect why this error is occuring?

Error: Request failed with status code 400
    at createError (C:\Users\jared\OneDrive\Documents\score_scraper\node_modules\axios\lib\core\createError.js:16:15)
    at settle (C:\Users\jared\OneDrive\Documents\score_scraper\node_modules\axios\lib\core\settle.js:17:12)
    at Unzip.handleStreamEnd (C:\Users\jared\OneDrive\Documents\score_scraper\node_modules\axios\lib\adapters\http.js:260:11)
    at Unzip.emit (events.js:315:20)
    at endReadableNT (internal/streams/readable.js:1327:12)
    at processTicksAndRejections (internal/process/task_queues.js:80:21) {
  config: {
    url: 'http://site.api.espn.com/apis/site/v2/sports/basketball/mens-college-basketball/scoreboard',
    method: 'get',
    headers: {
      Accept: 'application/json, text/plain, */*',
      'User-Agent': 'axios/0.21.1'
    },
    params: { dates: '2021215', group: 50, seasontype: null, limit: 1000 },
    transformRequest: [ [Function: transformRequest] ],
    transformResponse: [ [Function: transformResponse] ],
    timeout: 0,
    adapter: [Function: httpAdapter],
    xsrfCookieName: 'XSRF-TOKEN',
    xsrfHeaderName: 'X-XSRF-TOKEN',
    maxContentLength: -1,
    maxBodyLength: -1,
    validateStatus: [Function: validateStatus],
    data: undefined
  },
  request: <ref *1> ClientRequest {
    _events: [Object: null prototype] {
      socket: [Function (anonymous)],
      abort: [Function (anonymous)],
      aborted: [Function (anonymous)],
      connect: [Function (anonymous)],
      error: [Function (anonymous)],
      timeout: [Function (anonymous)],
      prefinish: [Function: requestOnPrefinish]
    },
    _eventsCount: 7,
    _maxListeners: undefined,
    outputData: [],
    outputSize: 0,
    writable: true,
    destroyed: true,
    _last: true,
    chunkedEncoding: false,
    shouldKeepAlive: false,
    _defaultKeepAlive: true,
    useChunkedEncodingByDefault: false,
    sendDate: false,
    _removedConnection: false,
    _removedContLen: false,
    _removedTE: false,
    _contentLength: 0,
    _hasBody: true,
    _trailer: '',
    finished: true,
    _headerSent: true,
    socket: Socket {
      connecting: false,
      _hadError: false,
      _parent: null,
      _host: 'site.api.espn.com',
      _readableState: [ReadableState],
      _events: [Object: null prototype],
      _eventsCount: 6,
      _maxListeners: undefined,
      _writableState: [WritableState],
      allowHalfOpen: false,
      _sockname: null,
      _pendingData: null,
      _pendingEncoding: '',
      server: null,
      _server: null,
      parser: null,
      _httpMessage: [Circular *1],
      [Symbol(async_id_symbol)]: 2,
      [Symbol(kHandle)]: null,
      [Symbol(kSetNoDelay)]: false,
      [Symbol(lastWriteQueueSize)]: 0,
      [Symbol(timeout)]: null,
      [Symbol(kBuffer)]: null,
      [Symbol(kBufferCb)]: null,
      [Symbol(kBufferGen)]: null,
      [Symbol(kCapture)]: false,
      [Symbol(kBytesRead)]: 551,
      [Symbol(kBytesWritten)]: 230,
      [Symbol(RequestTimeout)]: undefined
    },
    _header: 'GET /apis/site/v2/sports/basketball/mens-college-basketball/scoreboard?dates=2021215&group=50&limit=1000 HTTP/1.1\r\n' +
      'Accept: application/json, text/plain, */*\r\n' +
      'User-Agent: axios/0.21.1\r\n' +
      'Host: site.api.espn.com\r\n' +
      'Connection: close\r\n' +
      '\r\n',
    _keepAliveTimeout: 0,
    _onPendingData: [Function: noopPendingOutput],
    agent: Agent {
      _events: [Object: null prototype],
      _eventsCount: 2,
      _maxListeners: undefined,
      defaultPort: 80,
      protocol: 'http:',
      options: [Object],
      requests: {},
      sockets: {},
      freeSockets: {},
      keepAliveMsecs: 1000,
      keepAlive: false,
      maxSockets: Infinity,
      maxFreeSockets: 256,
      scheduling: 'fifo',
      maxTotalSockets: Infinity,
      totalSocketCount: 0,
      [Symbol(kCapture)]: false
    },
    socketPath: undefined,
    method: 'GET',
    maxHeaderSize: undefined,
    insecureHTTPParser: undefined,
    path: '/apis/site/v2/sports/basketball/mens-college-basketball/scoreboard?dates=2021215&group=50&limit=1000',
    _ended: true,
    res: IncomingMessage {
      _readableState: [ReadableState],
      _events: [Object: null prototype],
      _eventsCount: 1,
      _maxListeners: undefined,
      socket: [Socket],
      httpVersionMajor: 1,
      httpVersionMinor: 1,
      httpVersion: '1.1',
      complete: true,
      headers: [Object],
      rawHeaders: [Array],
      trailers: {},
      rawTrailers: [],
      aborted: false,
      upgrade: false,
      url: '',
      method: null,
      statusCode: 400,
      statusMessage: 'Bad Request',
      client: [Socket],
      _consuming: false,
      _dumped: false,
      req: [Circular *1],
      responseUrl: 'http://site.api.espn.com/apis/site/v2/sports/basketball/mens-college-basketball/scoreboard?dates=2021215&group=50&limit=1000',
      redirects: [],
      [Symbol(kCapture)]: false,
      [Symbol(RequestTimeout)]: undefined
    },
    aborted: false,
    timeoutCb: null,
    upgradeOrConnect: false,
    parser: null,
    maxHeadersCount: null,
    reusedSocket: false,
    host: 'site.api.espn.com',
    protocol: 'http:',
    _redirectable: Writable {
      _writableState: [WritableState],
      _events: [Object: null prototype],
      _eventsCount: 2,
      _maxListeners: undefined,
      _options: [Object],
      _ended: true,
      _ending: true,
      _redirectCount: 0,
      _redirects: [],
      _requestBodyLength: 0,
      _requestBodyBuffers: [],
      _onNativeResponse: [Function (anonymous)],
      _currentRequest: [Circular *1],
      _currentUrl: 'http://site.api.espn.com/apis/site/v2/sports/basketball/mens-college-basketball/scoreboard?dates=2021215&group=50&limit=1000',
      [Symbol(kCapture)]: false
    },
    [Symbol(kCapture)]: false,
    [Symbol(kNeedDrain)]: false,
    [Symbol(corked)]: 0,
    [Symbol(kOutHeaders)]: [Object: null prototype] {
      accept: [Array],
      'user-agent': [Array],
      host: [Array]
    }
  },
  response: {
    status: 400,
    statusText: 'Bad Request',
    headers: {
      'content-type': 'application/json;charset=UTF-8',
      'content-length': '73',
      pragma: 'no-cache',
      'access-control-allow-origin': '*',
      'access-control-allow-methods': 'GET,PUT,POST,DELETE,OPTIONS,HEAD',
      'access-control-expose-headers': 'content-length,location',
      link: '<scoreboard.json#>; rel="describedby"',
      vary: 'Accept-Encoding',
      'cache-control': 'max-age=1',
      expires: 'Tue, 23 Feb 2021 22:09:45 GMT',
      date: 'Tue, 23 Feb 2021 22:09:44 GMT',
      connection: 'close'
    },
    config: {
      url: 'http://site.api.espn.com/apis/site/v2/sports/basketball/mens-college-basketball/scoreboard',
      method: 'get',
      headers: [Object],
      params: [Object],
      transformRequest: [Array],
      transformResponse: [Array],
      timeout: 0,
      adapter: [Function: httpAdapter],
      xsrfCookieName: 'XSRF-TOKEN',
      xsrfHeaderName: 'X-XSRF-TOKEN',
      maxContentLength: -1,
      maxBodyLength: -1,
      validateStatus: [Function: validateStatus],
      data: undefined
    },
    request: <ref *1> ClientRequest {
      _events: [Object: null prototype],
      _eventsCount: 7,
      _maxListeners: undefined,
      outputData: [],
      outputSize: 0,
      writable: true,
      destroyed: true,
      _last: true,
      chunkedEncoding: false,
      shouldKeepAlive: false,
      _defaultKeepAlive: true,
      useChunkedEncodingByDefault: false,
      sendDate: false,
      _removedConnection: false,
      _removedContLen: false,
      _removedTE: false,
      _contentLength: 0,
      _hasBody: true,
      _trailer: '',
      finished: true,
      _headerSent: true,
      socket: [Socket],
      _header: 'GET /apis/site/v2/sports/basketball/mens-college-basketball/scoreboard?dates=2021215&group=50&limit=1000 HTTP/1.1\r\n' +
        'Accept: application/json, text/plain, */*\r\n' +
        'User-Agent: axios/0.21.1\r\n' +
        'Host: site.api.espn.com\r\n' +
        'Connection: close\r\n' +
        '\r\n',
      _keepAliveTimeout: 0,
      _onPendingData: [Function: noopPendingOutput],
      agent: [Agent],
      socketPath: undefined,
      method: 'GET',
      maxHeaderSize: undefined,
      insecureHTTPParser: undefined,
      path: '/apis/site/v2/sports/basketball/mens-college-basketball/scoreboard?dates=2021215&group=50&limit=1000',
      _ended: true,
      res: [IncomingMessage],
      aborted: false,
      timeoutCb: null,
      upgradeOrConnect: false,
      parser: null,
      maxHeadersCount: null,
      reusedSocket: false,
      host: 'site.api.espn.com',
      protocol: 'http:',
      _redirectable: [Writable],
      [Symbol(kCapture)]: false,
      [Symbol(kNeedDrain)]: false,
      [Symbol(corked)]: 0,
      [Symbol(kOutHeaders)]: [Object: null prototype]
    },
    data: { code: 400, message: 'Failed to get events endpoint.' }
  },
  isAxiosError: true,
  toJSON: [Function: toJSON]
}

Tests not failing

Working through adding tennis and I noticed that tests are not working as I expected. Always showing me a success, even when the URL is screwed up.

The promises seem to return after mocha spits out a success as well.

I'll look into mocha/chai and see what's going on. Not overly familiar with either.

My editor sees should as unused, so maybe there's a syntax issue here somewhere. I should have some time to look at it later tonight.

image

image

NCAA Game IDs

I think the NCAA changed something on their back end. The sdv.ncaaScoreboard.getNcaaScoreboard() call used to return an object where each game's url could be accessed and included the game ID and now it does not, which makes it impossible (unless I'm missing something) to get game IDs to feed into the box score and play by play functions.

old url: https://www.ncaa.com/game/3194201

new url: https://www.ncaa.com/game/basketball-men/d3/2019/02/15/whitman-puget-sound

The new url redirects to the old one when putting it directly into the browser, fwiw. Not sure how you can revert it to the old url or if there's another way to get the game ID, but it would be awesome if possible.

Error when importing

I'm new to nodejs and I can't figure out how I'm supposed to import the package. My index.js looks like this:

const sdv = require("sportsdataverse")

But when I run it gives me this error:

/Users/campbelljlowman/Documents/Code/Sandbox/sports_data/node_modules/sportsdataverse/app/services/ncaa.service.js:4
const tabletojson = require("tabletojson").Tabletojson;
^

Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/campbelljlowman/Documents/Code/Sandbox/sports_data/node_modules/tabletojson/dist/lib/index.js from /Users/campbelljlowman/Documents/Code/Sandbox/sports_data/node_modules/sportsdataverse/app/services/ncaa.service.js not supported.
Instead change the require of index.js in /Users/campbelljlowman/Documents/Code/Sandbox/sports_data/node_modules/sportsdataverse/app/services/ncaa.service.js to a dynamic import() which is available in all CommonJS modules.
at Object. (/Users/campbelljlowman/Documents/Code/Sandbox/sports_data/node_modules/sportsdataverse/app/services/ncaa.service.js:4:21)
at Object. (/Users/campbelljlowman/Documents/Code/Sandbox/sports_data/node_modules/sportsdataverse/app/app.js:6:23)
at Object. (/Users/campbelljlowman/Documents/Code/Sandbox/sports_data/node_modules/sportsdataverse/server.js:3:13)
at Object. (/Users/campbelljlowman/Documents/Code/Sandbox/sports_data/index.js:1:13) {
code: 'ERR_REQUIRE_ESM'
}

Node.js v18.16.0

If I change my package type to "module", I get the same error

It doesn't seem like anyone else has had this problem, so I'm thinking it's something to do with my setup. Any help would be appreciated :)

Issue getting standings for most sports

// get standings
const inputs = {
    year: 2020,
    group: 'league'
};

const result = await sdv.nba.getStandings(inputs);

Followed this exact code when trying to get NBA standings, but it keeps returning a pending Promise and then gives me a TypeError of "Cannot read property 'standings' of undefined". The function is clearly calling, but there might be an issue with the template literal. Also on the documentation website, "group"'s type is a Number? Is there a new way to get standings? Tested this method with every professional sports league (with its relevant parameters in the docs) and none of them work. Please let me know if that method has been deprecated.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.