Exemplo n.º 1
0
class NBAScrapeBase(object):
    session = None
    game_years_map = {"2001":16, "2002": 67, "2003": 95, "2004":112, "2005":131,
                      "2006":165, "2007": 187, "2008": 211, "2009":234, "2010":249,
                      "2011":265, "2012": 304, "2013":322
                      }
    statkey_var_map ={"0":"gp",
                      "1":"gs",
                      "2":"mp",
                      "3":"fga",
                      "4":"fgm",
                      "5":"fgp",
                      "6":"fta",
                      "7":"ftm",
                      "8":"ftp",
                      "9":"fga3",
                      "10":"fgm3",
                      "11":"fgp3",
                      "12":"pts",
                      "13":"oreb",
                      "14":"dreb",
                      "15":"reb",
                      "16":"ast",
                      "17":"stl",
                      "18":"blk",
                      "19":"tov",
                      "21":"pf"
                      }
    special_statkey_map ={
                      "9004003":"fgm/fga",
                      "9007006":"ftm/fta"
                      }
    
    percentages_stats = ["fgp", "ftp", "fgp3"]
    
    def __init__(self, push_to_db = False):
        # Have checks on session to see if the request was successful.
        if not self.session:
            self.session = YahooOAuth().session
        self.getLeagueKey()
        self.entityManager = EntityManager()
        self.getTeams()
        #self.getPlayers()
        self.push_to_db = push_to_db
    
    def getGameKey(self, year=2013):
        year_str = str(year)
        return self.game_years_map[year_str];
    
    def getLeagueKey(self):
        # Remember to format this.
        league_key_url = "http://fantasysports.yahooapis.com/fantasy/v2/users;use_login=1/games;game_keys=322/leagues"
        self.league_key_url = self.session.get(league_key_url.format(self.getGameKey()))
        
    def getTeams(self):
        self.nba_teams = self.entityManager.cur.query(NBATeam).all()
        
    def getPlayers(self):
        self.players = self.entityManager.cur.query(Player).all()
Exemplo n.º 2
0
 def __init__(self, push_to_db = False):
     # Have checks on session to see if the request was successful.
     if not self.session:
         self.session = YahooOAuth().session
     self.getLeagueKey()
     self.entityManager = EntityManager()
     self.getTeams()
     #self.getPlayers()
     self.push_to_db = push_to_db