def import_file(self, html_file): """ Imports a single HTMLFile into the database, parsing as appropriate. The team is created if it doesn't already exist """ team = None with self.session_scope() as session: # find team in the database team_id = parse_team_id(html_file.HTML) result = session.query(Team).filter_by(id=team_id) if(result.count()): team = result.first() else: # no team, so create it team = Team() team.id = team_id # pass the html to the appropriate parsing function if(html_file.type == PageTypes.Pavilion.value): team.add_ranking(parse_pavilion(html_file.HTML)) elif(html_file.type == PageTypes.Squad.value): team.players = parse_players(html_file.HTML) # add the team and HTML file to the database session.add(team) session.add(html_file) session.flush() return html_file
def test_parse_team_id_parses_id(): file = open(path.join(getcwd(), "test", "resources", "squad.html"), "r") html = file.read() teamID = parse_team_id(html) assert_equal(teamID, 30438)