Beispiel #1
0
def getGoalieStats(s):

    '''
        Add Goalie Stats to the database
    '''


    # url = "http://ottawatravellers.ca/W1516/skater-standings/Div%2012/"
    url = global_season.goalies_url

    if s == "":
        cseason = season.objects.get_or_create(year=global_season.year, season=global_season.season)
    else:
        cseason = s

    html = urllib2.urlopen(url)

    table = BeautifulSoup(html, 'html.parser').table

    rows = table.find_all('tr')

    for row in rows:
        # print row
        cells = row.find_all("td")

        if cells:

                currentplayer, valid = players.objects.get_or_create(name=cells[1].get_text().lower())
                playerTeam, valid = team.objects.get_or_create(name=cells[2].get_text())

                position, valid = playerPosition.objects.get_or_create(player=currentplayer, team=playerTeam, position="Goalie")

                gamesPlayed = cells[3].get_text()
                wins = cells[5].get_text()
                loses = cells[6].get_text()
                ties = cells[7].get_text()
                goalsAgainst = cells[8].get_text()
                goalsAgainstAverage = cells[9].get_text()
                shutOuts = cells[10].get_text()
                goals = cells[11].get_text()
                assists = cells[12].get_text()


                try:
                    #Lets try to add the player stat
                    addStat = playerStats(player=currentplayer, playerPosition=position, gamesPlayed=gamesPlayed, team=playerTeam, season=cseason, goals=goals, assists=assists, wins=wins, loses=loses, ties=ties, goalsAgainst = goalsAgainst, goalsAgainstAverage=goalsAgainstAverage, shutOuts=shutOuts)
                    addStat.save()

                    addTeamLink = playerTeam(player=currentplayer, team=playerTeam)
                    addTeamLink.save()
                except:
                    #If Stat exists update record
                    #first find the player
                    playerStat = playerStats.objects.filter(player=currentplayer, playerPosition__position="Goalie", season=cseason, team=playerTeam).update(gamesPlayed=gamesPlayed, wins=wins, loses=loses, ties=ties, goalsAgainst = goalsAgainst, goalsAgainstAverage=goalsAgainstAverage, shutOuts=shutOuts)

                    print "stat exists"
Beispiel #2
0
def getPlayerStats(s):

    # url = "http://ottawatravellers.ca/W1516/skater-standings/Div%2012/"

    if s == "":
        cseason = season.objects.get_or_create(year=global_season.year, season=global_season.season)[0]
    else:
        cseason = s

    url = global_season.skaters_url
    html = urllib2.urlopen(url)

    table = BeautifulSoup(html, 'html.parser').table

    rows = table.find_all('tr')

    for row in rows:
        # print row
        cells = row.find_all("td")

        if cells:

                currentplayer, valid = players.objects.get_or_create(name=cells[2].get_text().lower())
                playerTeam, valid = team.objects.get_or_create(name=cells[3].get_text())

                position, valid = playerPosition.objects.get_or_create(player=currentplayer, team=playerTeam, position="skater")


                gamesPlayed = cells[4].get_text()
                goals = cells[6].get_text()
                assists = cells[7].get_text()
                points = cells[8].get_text()
                penalties = cells[12].get_text()
                penaltyMins = cells[14].get_text()
                powerPlayGoals = cells[16].get_text()
                shortHandedGoales = cells[17].get_text()



                # currentSeason = season.objects.get(season="winter", year=2015)

                #Add player stats to DB
                # addStat = playerStats(player=currentplayer, team=playerTeam, season=currentSeason, goals=goals, assists=assists, points=points, penalties=penalties, penaltyMins=penaltyMins, powerPlayGoals=powerPlayGoals, shortHandedGoales=shortHandedGoales)
                # addStat.save()
                try:
                    addStat = playerStats(player=currentplayer, playerPosition=position, gamesPlayed=gamesPlayed, team=playerTeam, season=cseason, goals=goals, assists=assists, points=points, penalties=penalties, penaltyMins=penaltyMins, powerPlayGoals=powerPlayGoals, shortHandedGoales=shortHandedGoales)
                    addStat.save()
                except:
                    #If Stat exists update record
                    #first find the player
                    playerStat = playerStats.objects.filter(player=currentplayer, playerPosition__position="skater",team=playerTeam, season=cseason ).update(gamesPlayed=gamesPlayed, goals=goals, assists=assists, points=points, penalties=penalties, penaltyMins=penaltyMins, powerPlayGoals=powerPlayGoals, shortHandedGoales=shortHandedGoales)

                    print "stat exists"