diff options
Diffstat (limited to 'jfr_playoff/tournamentinfo')
-rw-r--r-- | jfr_playoff/tournamentinfo/__init__.py | 47 |
1 files changed, 16 insertions, 31 deletions
diff --git a/jfr_playoff/tournamentinfo/__init__.py b/jfr_playoff/tournamentinfo/__init__.py index 67cc8f6..21cd62a 100644 --- a/jfr_playoff/tournamentinfo/__init__.py +++ b/jfr_playoff/tournamentinfo/__init__.py @@ -1,4 +1,5 @@ from jfr_playoff.logger import PlayoffLogger +from jfr_playoff.data import ResultInfo class TournamentInfoClient(object): @@ -19,22 +20,26 @@ class TournamentInfoClient(object): pass -class TournamentInfo: +class TournamentInfo(ResultInfo): def __init__(self, settings, database): self.settings = settings + ResultInfo.__init__(self, settings, database) + + def fill_client_list(self, settings, database): + clients = [] from jfr_playoff.tournamentinfo.jfrdb import JFRDbTournamentInfo from jfr_playoff.tournamentinfo.jfrhtml import JFRHtmlTournamentInfo from jfr_playoff.tournamentinfo.tcjson import TCJsonTournamentInfo - self.clients = [] - if (database is not None) and ('database' in self.settings): - self.clients.append(JFRDbTournamentInfo(settings, database)) - if 'link' in self.settings: - if self.settings['link'].endswith('leaderb.html'): - self.clients.append(JFRHtmlTournamentInfo(settings)) - self.clients.append(TCJsonTournamentInfo(settings)) + if (database is not None) and ('database' in settings): + clients.append(JFRDbTournamentInfo(settings, database)) + if 'link' in settings: + if settings['link'].endswith('leaderb.html'): + clients.append(JFRHtmlTournamentInfo(settings)) + clients.append(TCJsonTournamentInfo(settings)) + return clients def get_tournament_results(self): - teams = self.__call_client('get_tournament_results', []) + teams = self.call_client('get_tournament_results', []) if self.is_finished(): final_positions = self.settings.get('final_positions', []) PlayoffLogger.get('tournamentinfo').info( @@ -47,27 +52,7 @@ class TournamentInfo: return teams def is_finished(self): - return self.__call_client('is_finished', True) + return self.call_client('is_finished', True) def get_results_link(self, suffix='leaderb.html'): - return self.__call_client('get_results_link', None, suffix) - - def __call_client(self, method, default, *args): - PlayoffLogger.get('tournamentinfo').info( - 'calling %s on tournament info clients', method) - for client in self.clients: - try: - ret = getattr(client, method)(*args) - PlayoffLogger.get('tournamentinfo').info( - '%s method returned %s', method, ret) - return ret - except Exception as e: - if type(e) in client.get_exceptions(method): - PlayoffLogger.get('tournamentinfo').warning( - '%s method raised %s(%s)', - method, type(e).__name__, str(e)) - else: - raise - PlayoffLogger.get('tournamentinfo').info( - '%s method returning default: %s', method, default) - return default + return self.call_client('get_results_link', None, suffix) |