Coder Social home page Coder Social logo

node_scrapr's Introduction

#Node.js NHL Scrapr This is a basic RESTful API which fetches event data and shift tables from the NHL's HTM tables and returns them as a handy-dandy JSON. The JSON is stored in the database, and every future GET request will simply fetch it from the db.

##End Points

// fetch all game ids
$.JSON("/ids", function (data) {
  // do stuff
});

// fetch event JSON for game ID XXXXXX
$.JSON("/events/:id", function (data) {
  // do stuff
});

//fetch shift JSON for gameID (TH|TV)XXXXXX
$.JSON("/shifts/:id", function (data) {
  //do stuff
});

##Example Here, I get the game IDs for Philadelphia for the 2016-2017 season using the /id endpoint. To specify a team, add the team's abbreviation in query form.

// fetch all game ids for Philadelphia (PHI)
var idList;
$.JSON("/ids?team=PHI", function (data) {
  idList = data.map(function (game) {
    //game id comes in form YYYYXXXXXXX (integer)
    return {
      home: game.h === "PHI",
      id: ("0" + game.id % 1000000).slice(-6) // will give us last 6 digits including leading 0
    }
  })
});

Great! We now have a list of 6 digit ids stored for PHI, along with whether the game is home or away. Now, say we want to fetch the event data for their 7th game of the season...

// 6th index is 7th entry
var idObject = idList[6];
var id = idObject.id;

$.JSON("/events/" + id, function (data) {
  // do something with the data;
});

Sample of Above Data

[
  {
    "_id": "586d5c9d53bc215c740bc592",
    "id": 2016020016,
    "est": "20161014 22:30:00",
    "a": "PHI",
    "h": "LAK"
  },
  {
    "_id": "586d5c9d53bc215c740bc59e",
    "id": 2016020028,
    "est": "20161015 21:00:00",
    "a": "PHI",
    "h": "ARI"
  },
  {
    "_id": "586d5c9d53bc215c740bc5af",
    "id": 2016020045,
    "est": "20161018 20:30:00",
    "a": "PHI",
    "h": "CHI"
  },
]

Now, let's get the shift data for the same game. It's important to note that a prefix of either TH (home) or TV (visitor) is needed, along with the id, to get that data.

var prefix = (idObject.home) ? "TH" : "TV";

$.JSON("/shifts/" + prefix + id, function (data) {
  // do something with shift data
});

Example Shift Data

Actual shift data includes all players.

"docs": [
    {
      "player": "9 PROVOROV, IVAN",
      "data": {
        "shifts": [
          {
            "shift": 1,
            "per": 1,
            "start": "0:27 / 19:33",
            "end": "1:00 / 19:00",
            "duration": "00:33",
            "event": " "
          },
          {
            "shift": 2,
            "per": 1,
            "start": "2:45 / 17:15",
            "end": "3:13 / 16:47",
            "duration": "00:28",
            "event": " "
          },
          {
            "shift": 3,
            "per": 1,
            "start": "5:44 / 14:16",
            "end": "6:33 / 13:27",
            "duration": "00:49",
            "event": " "
          },
        ]
      }
    }
  ]

node_scrapr's People

Contributors

andrew-pete avatar

Watchers

James Cloos avatar  avatar

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.