Beispiel #1
0
    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_pavilion_throws_BatParseException_if_no_pavilion_info():
    parse_pavilion("html with no pavilion info")
 def setUpClass(cls):
     file = open(path.join(getcwd(), "test", "resources", "pavilion.html"), "r")
     html = file.read()
     cls.ranking = parse_pavilion(html)
     file.close()