Git Product home page Git Product logo

nhl_data's Introduction

NHL_data

This repo is a Python project that is attempting to scrape all individual season data from NHL.com and prepare it to be copied into a SQL database.

Setup

Python environment

  • Create a virtual environment (if desired)
  • pip install -r requirements.txt

PostgreSQL

Follow the instructions here. You'll need a local server running to load data into, or perhaps something hosted with connection information to configure later.

I installed postgres via apt, then created a user and database:

sudo apt install postgresql
su -u postgres createuser -D -A -P myusername
su -u postgres createdb -O myusername mydatabase

Data Collection

The script should just run (within the virtual environment) via

python scrape.py

We can then put that data into our database with the following set of commands:

psql -U myusername -d mydatabase -f create_db.sql
psql -U myusername -d mydatabase -c "\copy players FROM './data/player_bios.csv' delimiter ',' csv header;"
psql -U myusername -d mydatabase -c "\copy player_teams FROM './data/player_teams.csv' delimiter ',' csv header;"
psql -U myusername -d mydatabase -c "\copy skater_stats FROM './data/skater_data.csv' delimiter ',' csv header;"
psql -U myusername -d mydatabase -c "\copy goalie_stats FROM './data/goalie_data.csv' delimiter ',' csv header;"

We need to put the \copy commands outside the script as postgres will not allow them from inside a script easily. It may be possible, but this seemed easier than setting up authentication.

Data Update

With the database built, it should now be a relatively simple matter to collect data from the ongoing season and update the tables. The update.py script does this by scraping data for the current season (set in the script), dropping data collected so far (except bios, for which we note only new players), then appending the newly scraped data to the existing tables.

Potential Improvements

  • Scrape season standings, schedule
  • Pull settings into a global settings file
  • Remove the need for bash scripts by using SQLAlchemy to create the initial tables

nhl_data's People

Contributors

kielejocain avatar

Watchers

James Cloos avatar  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.