summaryrefslogtreecommitdiff
path: root/jfr_playoff
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2018-02-21 13:04:25 +0100
committeremkael <emkael@tlen.pl>2018-02-21 13:04:25 +0100
commit10551e02f10d42ae47006036061e21ff561e8088 (patch)
treea9211961f3ce95bd3622eb48ec79db3daeef4b36 /jfr_playoff
parent8bdcae7b37b7e7d356cd7d63c0ea63da584f95fe (diff)
Compiling match links from given remote URL
Diffstat (limited to 'jfr_playoff')
-rw-r--r--jfr_playoff/tournamentinfo.py36
1 files changed, 25 insertions, 11 deletions
diff --git a/jfr_playoff/tournamentinfo.py b/jfr_playoff/tournamentinfo.py
index d45815f..586a623 100644
--- a/jfr_playoff/tournamentinfo.py
+++ b/jfr_playoff/tournamentinfo.py
@@ -63,6 +63,25 @@ class TournamentInfo:
self.settings['database'], p_sql.SWISS_ENDED, {})
return (len(finished) > 0) and (finished[0] > 0)
+ def __get_html_link(self, suffix='leaderb.html'):
+ if 'link' not in self.settings:
+ raise KeyError('link not configured')
+ if not self.settings['link'].endswith('leaderb.html'):
+ raise ValueError('unable to determine html link')
+ return re.sub(r'leaderb.html$', suffix, self.settings['link'])
+
+ def __get_db_link(self, suffix='leaderb.html'):
+ if self.database is None:
+ raise KeyError('database not configured')
+ if 'database' not in self.settings:
+ raise KeyError('database not configured')
+ row = self.database.fetch(
+ self.settings['database'], p_sql.PREFIX, ())
+ if row is not None:
+ if len(row) > 0:
+ return row[0] + suffix
+ raise ValueError('unable to fetch db link')
+
def get_tournament_results(self):
try:
return self.__get_db_results()
@@ -84,16 +103,11 @@ class TournamentInfo:
return True
def get_results_link(self, suffix='leaderb.html'):
- if self.database is None:
- return None
- if 'database' not in self.settings:
- return None
try:
- row = self.database.fetch(
- self.settings['database'], p_sql.PREFIX, ())
- if row is not None:
- if len(row) > 0:
- return row[0] + suffix
- except mysql.connector.Error:
- return None
+ return self.__get_db_link(suffix)
+ except (mysql.connector.Error, TypeError, IndexError, KeyError):
+ try:
+ return self.__get_html_link(suffix)
+ except (KeyError, ValueError):
+ pass
return None