diff options
author | emkael <emkael@tlen.pl> | 2019-12-30 21:08:45 +0100 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2019-12-30 21:08:45 +0100 |
commit | 8230739ccf52970a61c68f414f0cf2812b79f766 (patch) | |
tree | 80bfc95746817447f3824b9f376e8157371778e8 | |
parent | 885b6773ef59613594f45fa3941797e053931a15 (diff) |
Match links fetched via result info client mechanism
-rw-r--r-- | jfr_playoff/data/info.py | 22 | ||||
-rw-r--r-- | jfr_playoff/data/match/__init__.py | 6 | ||||
-rw-r--r-- | jfr_playoff/data/match/jfrdb.py | 28 | ||||
-rw-r--r-- | jfr_playoff/data/match/jfrhtml.py | 20 | ||||
-rw-r--r-- | jfr_playoff/data/match/tcjson.py | 26 |
5 files changed, 91 insertions, 11 deletions
diff --git a/jfr_playoff/data/info.py b/jfr_playoff/data/info.py index f36b003..142abf4 100644 --- a/jfr_playoff/data/info.py +++ b/jfr_playoff/data/info.py @@ -143,18 +143,12 @@ class MatchInfo(ResultInfo): self.info.teams = [] def __fetch_match_link(self): - if 'link' in self.config: - self.info.link = self.config['link'] - PlayoffLogger.get('matchinfo').info( - 'match #%d link pre-defined: %s', self.info.id, self.info.link) - elif ('round' in self.config) and ('database' in self.config): - event_info = TournamentInfo(self.config, self.database) - self.info.link = event_info.get_results_link( - 'runda%d.html' % (self.config['round'])) - PlayoffLogger.get('matchinfo').info( - 'match #%d link fetched: %s', self.info.id, self.info.link) + link = self.call_client('get_match_link', None) + if link is not None: + self.info.link = link else: - PlayoffLogger.get('matchinfo').info('match #%d link empty', self.info.id) + PlayoffLogger.get('matchinfo').info( + 'match #%d link empty', self.info.id) def __get_predefined_scores(self): teams = [Team(), Team()] @@ -561,6 +555,12 @@ class MatchInfo(ResultInfo): PlayoffLogger.get('matchinfo').info( 'applying phase link %s to match #%d: %s', phase_link, self.info.id, self.info.link) + # re-init result info clients + if not len(self.clients) and (self.info.link is not None): + PlayoffLogger.get('matchinfo').info( + 'config link changed, re-initializing result info client list') + self.config['link'] = self.info.link + ResultInfo.__init__(self, self.config, self.database) def get_info(self): self.__fetch_teams_with_scores() diff --git a/jfr_playoff/data/match/__init__.py b/jfr_playoff/data/match/__init__.py index e69de29..7db05c2 100644 --- a/jfr_playoff/data/match/__init__.py +++ b/jfr_playoff/data/match/__init__.py @@ -0,0 +1,6 @@ +from jfr_playoff.data.info import ResultInfoClient + + +class MatchInfoClient(ResultInfoClient): + def get_match_link(self): + raise NotImplementedError diff --git a/jfr_playoff/data/match/jfrdb.py b/jfr_playoff/data/match/jfrdb.py new file mode 100644 index 0000000..7d9e067 --- /dev/null +++ b/jfr_playoff/data/match/jfrdb.py @@ -0,0 +1,28 @@ +from jfr_playoff.data import TournamentInfo +from jfr_playoff.data.match import MatchInfoClient +from jfr_playoff.logger import PlayoffLogger + + +class JFRDbMatchInfo(MatchInfoClient): + @property + def priority(self): + return 50 + + def is_capable(self): + return (self.database is not None) and ('database' in self.settings) + + def get_exceptions(self, method): + return (IOError, TypeError, IndexError, KeyError) + + def get_match_link(self): + if 'link' in self.settings: + raise NotImplementedError( + 'link specified in config, skipping lookup') + if 'round' not in self.settings: + raise IndexError('round number not specified in match config') + event_info = TournamentInfo(self.settings, self.database) + link = event_info.get_results_link( + 'runda%d.html' % (self.settings['round'])) + PlayoffLogger.get('match.jfrdb').info( + 'match #%d link fetched: %s', self.settings['id'], link) + return link diff --git a/jfr_playoff/data/match/jfrhtml.py b/jfr_playoff/data/match/jfrhtml.py new file mode 100644 index 0000000..40f1395 --- /dev/null +++ b/jfr_playoff/data/match/jfrhtml.py @@ -0,0 +1,20 @@ +from jfr_playoff.data.match import MatchInfoClient +from jfr_playoff.logger import PlayoffLogger + + +class JFRHtmlMatchInfo(MatchInfoClient): + @property + def priority(self): + return 30 + + def is_capable(self): + return ('link' in self.settings) and ('#' not in self.settings['link']) + + def get_exceptions(self, method): + return (TypeError, IndexError, KeyError, IOError, ValueError) + + def get_match_link(self): + PlayoffLogger.get('match.jfrhtml').info( + 'match #%d link pre-defined: %s', + self.settings['id'], self.settings['link']) + return self.settings['link'] diff --git a/jfr_playoff/data/match/tcjson.py b/jfr_playoff/data/match/tcjson.py new file mode 100644 index 0000000..fbc28ce --- /dev/null +++ b/jfr_playoff/data/match/tcjson.py @@ -0,0 +1,26 @@ +import urlparse + +from jfr_playoff.data.match import MatchInfoClient +from jfr_playoff.logger import PlayoffLogger + + +class TCJsonMatchInfo(MatchInfoClient): + @property + def priority(self): + return 20 + + def is_capable(self): + return ('link' in self.settings) and ('#' in self.settings['link']) + + def get_exceptions(self, method): + return (TypeError, IndexError, KeyError, IOError, ValueError) + + def _get_round_from_link(self, link): + fragment = urlparse.urlparse(link).fragment + return fragment[11:14], fragment[14:17] + + def get_match_link(self): + PlayoffLogger.get('match.tcjson').info( + 'match #%d link pre-defined: %s', + self.settings['id'], self.settings['link']) + return self.settings['link'] |