Exemplo n.º 1
0
def create_divisions(division_src_file):
    lines = open(division_src_file).readlines()

    session = Session()
    try:
        for line in lines:
            if line.startswith("#"):
                continue
            division_name, season, teams, conference = line.strip().split(";")
            season = int(season)
            team_abbrs = teams[1:-1].split(",")
            teams = list()
            for t in team_abbrs:
                team = NHLTeam.find(t)
                teams.append(team)
            else:
                if conference:
                    division = NHLDivision(division_name, season, teams, conference)
                else:
                    division = NHLDivision(division_name, season, teams)
                session.add(division)

                ids = "{" + ",".join([str(t.team_id) for t in teams]) + "}"
                if conference:
                    output = "%s Division (%s Conference):\t%d\t%s" % (division_name, conference, season, ids)
                else:
                    output = "%s Division:\t%d\t%s" % (division_name, season, ids)
                print output
        else:
            session.commit()
    except:
        session.rollback()
Exemplo n.º 2
0
 def get_divisions_and_teams(cls, year):
     session = Session()
     divs = session.query(NHLDivision).filter(NHLDivision.year == year).all()
     for d in divs:
         teams = list()
         for team_id in d.teams:
             team = NHLTeam.find_by_id(team_id)
             teams.append(team)
         print d.division_name
         for t in teams:
             print "\t", t