-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
47,108 additions
and
175 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
3,214 changes: 3,214 additions & 0 deletions
3,214
scraper/.ipynb_checkpoints/Untitled-checkpoint.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1,218 changes: 1,218 additions & 0 deletions
1,218
scraper/.ipynb_checkpoints/transform-checkpoint.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from scrapy.spiders import CrawlSpider, Rule | ||
from scrapy.linkextractors import LinkExtractor | ||
from datetime import datetime as dt, timedelta as td | ||
import json | ||
from os.path import join, expanduser | ||
|
||
def game_dates(): | ||
start_date = dt(1996,10,8) | ||
end_date = dt.today() | ||
|
||
days = (end_date - start_date).days | ||
|
||
for i in range(days): | ||
yield 'https://www.nba.com/games?date='+dt.strftime(start_date + td(i+1), '%Y-%m-%d') | ||
|
||
class GamesSpider(CrawlSpider): | ||
name = 'pbp-games' | ||
allowed_domains = ['nba.com'] | ||
start_urls = list(game_dates()) | ||
REDIRECT_ENABLED = False | ||
|
||
rules = [Rule(LinkExtractor(allow=['\w+-vs-\w+-\d+/box-score#box-score']), callback='parse_page')] | ||
|
||
def parse_page(self, response): | ||
items = response.css('script[type="application/json"]::text') | ||
|
||
extract_path = expanduser(join('~','spark_apps','games')) | ||
|
||
for i in items: | ||
to_write = json.loads(i.get())['props']['pageProps'] | ||
fname = join(extract_path, to_write['playByPlay']['gameId'] + '.json') | ||
with open(fname, 'w') as fp: | ||
json.dump(to_write, fp) |
Large diffs are not rendered by default.
Oops, something went wrong.