Permalink
Browse files

Fork of code from ScraperWiki at https://classic.scraperwiki.com/scra…

  • Loading branch information...
tonycpsu committed May 28, 2014
0 parents commit 75d2748ed5da9991c29f7bdf77c56b6eb3056177
Showing with 57 additions and 0 deletions.
  1. +2 −0 .gitignore
  2. +1 −0 README.textile
  3. +54 −0 scraper.py
@@ -0,0 +1,2 @@
# Ignore output of scraper
data.sqlite
@@ -0,0 +1 @@
Generates MLB Scheduled games for the day the scrapper is executed.
@@ -0,0 +1,54 @@
import datetime
import scraperwiki
import re
from string import Template
import demjson
import time
sdate = datetime.datetime.now()
sdate_split = str(sdate.year) + str(sdate.month) + str(sdate.day)
# json1 = scraperwiki.scrape("http://mlb.mlb.com/components/schedule/schedule_" + sdate_split + ".json")
json1 = scraperwiki.scrape("http://mlb.mlb.com/components/schedule/schedule_20130930.json")
json_decode1 = demjson.decode(json1)
for i in range (len(json_decode1)) :
game = json_decode1[i]
game_id_split = game['game_id'].split('/')
game_date = game_id_split[0] + game_id_split[1] + game_id_split[2]
record = {}
record['game_pk'] = game['game_pk']
record['game_type'] = game['game_type']
timeinsecs = (int(game['game_time'])*0.001)- (4 * 60 * 60)
record['game_time_et'] = time.ctime(timeinsecs)
record['venue'] = game['game_venue']
record['venue_id'] = game['venue_id']
record['time'] = game['game_time']
record['location'] = game['game_location']
record['game_id'] = game['game_id']
record['home_team_fc'] = game['home']['file_code']
record['away_team_fc'] = game['away']['file_code']
record['home_team_id'] = game['home']['id']
record['away_team_id'] = game['away']['id']
record['game_id'] = game['game_id']
record['game_date'] = game_date
record['home_prob_id'] = game['home']['probable_id']
record['home_probable'] = game['home']['probable']
record['home_prob_era'] = game['home']['probable_era']
record['home_prob_stat'] = game['home']['probable_stat']
record['away_prob_id'] = game['away']['probable_id']
record['away_prob_stat'] = game['away']['probable_stat']
record['away_probable'] = game['away']['probable']
record['away_prob_era'] = game['away']['probable_era']
record['sport_code'] = game['sport_code']
#print record
if record.has_key('game_pk'):
# save records to the datastore
scraperwiki.sqlite.save(['game_pk'],record)

0 comments on commit 75d2748

Please sign in to comment.