import urllib
from BeautifulSoup import BeautifulSoup

# some constants
GAME_DAY_URL = "http://livescores.afl.com.au/all-matches.html"

"""
    Uses game day live to find the score for the given team in their game in the
    current round.

    Returns a list of 6 elements containing the team name, scores for each qtr and 
    total/final
"""
def get_score(team):
    # Grab the Game Day Live HTML page
    f = urllib.urlopen(GAME_DAY_URL)
    all_matches = f.read()
    f.close()

    soup = BeautifulSoup(all_matches)
    # get all the <span> tags
    spans = soup.findAll('span')

    team = team.upper()

    fetch = 0
    scores = []
    scores.append(team)
    for s in spans:
        s = unicode(s)
        if fetch > 0:
            score = s
            score = score.replace("<span>", "").replace("</span>", "")
            scores.append(score)
            fetch -= 1
        elif s.find(team) != -1:
            fetch = 5

    return scores
