def run_gid(gid, gametype): retries = 0 while retries < 10: try: DB = store.Store() g = game.Game(gid) if (g.game_type != gametype): return g.save() game_id = g.game_id ab = atbats.AtBats(gid, game_id) ab.save() chart = hitchart.HitChart(gid, game_id) chart.save() batters = players.Batters(gid, game_id) batters.save() pitchers = players.Pitchers(gid, game_id) pitchers.save() DB.finish() break except Exception as e: print "EXCEPTION: %s, RETRIES: %s" % (e, retries) retries += 1
def run(self): DB = store.Store() soup = BeautifulSoup(Fetcher.fetch(self.url)) for link in soup.findAll('a'): if link['href'].find('gid_') >= 0: gid = link['href'].rstrip('/') g = game.Game(gid) if (g.game_type != self.gametype): continue g.save() game_id = g.game_id ab = atbats.AtBats(gid, game_id) ab.save() chart = hitchart.HitChart(gid, game_id) chart.save() batters = players.Batters(gid, game_id) batters.save() pitchers = players.Pitchers(gid, game_id) pitchers.save()
if __name__ == '__main__': TYPE = 'mlb' YEAR = None MONTH = None DAY = None VERBOSE = False DELTA = False log = logging.getLogger('gameday') startday = 1 startmonth = 1 # here lies a hack for the strptime thread bug foo = strptime('30 Nov 00', '%d %b %y') try: DB = store.Store() except MySQLdb.Error, e: print 'Database connection problem- did you setup a db.ini? (error: %s)' % e raise SystemExit try: opts, args = getopt( argv[1:], '', ['verbose', 'delta', 'year=', 'month=', 'day=', 'type=']) except: usage() for opt, arg in opts: if opt == '--verbose': VERBOSE = True elif opt == '--year':