From ab371e10931e1c42877a0758cdcb2144e886850f Mon Sep 17 00:00:00 2001 From: emkael Date: Sat, 17 Feb 2018 15:21:29 +0100 Subject: If a match is running, link to first unfinished segment Fixes #6 --- jfr_playoff/matchinfo.py | 18 ++++++++++++++++++ jfr_playoff/sql.py | 5 +++++ 2 files changed, 23 insertions(+) (limited to 'jfr_playoff') diff --git a/jfr_playoff/matchinfo.py b/jfr_playoff/matchinfo.py index 9366d5f..9f446cc 100644 --- a/jfr_playoff/matchinfo.py +++ b/jfr_playoff/matchinfo.py @@ -1,3 +1,4 @@ +import re from urlparse import urljoin import mysql @@ -169,6 +170,21 @@ class MatchInfo: self.info.loser = self.info.teams[0].name self.info.winner = self.info.teams[1].name + def __get_db_running_link(self, prefix, round_no): + current_segment = int( + self.database.fetch( + self.config['database'], p_sql.CURRENT_SEGMENT, ())[0]) + return '%s%st%d-%d.html' % ( + prefix, round_no, self.config['table'], current_segment) + + def __determine_running_link(self): + link_match = re.match(r'^(.*)runda(\d+)\.html$', self.info.link) + if link_match: + try: + self.info.link = self.__get_db_running_link( + link_match.group(1), link_match.group(2)) + except (mysql.connector.Error, TypeError, IndexError, KeyError): + pass def set_phase_link(self, phase_link): if self.info.link is None: @@ -181,4 +197,6 @@ class MatchInfo: self.__fetch_teams_with_scores() self.__fetch_board_count() self.__determine_outcome() + if self.info.running > 0: + self.__determine_running_link() return self.info diff --git a/jfr_playoff/sql.py b/jfr_playoff/sql.py index ab6d0be..1eac414 100644 --- a/jfr_playoff/sql.py +++ b/jfr_playoff/sql.py @@ -33,6 +33,11 @@ WHERE #db#.segments.tabl = %s AND #db#.segments.rnd = %s GROUP BY #db#.segments.tabl, #db#.segments.rnd ''' +CURRENT_SEGMENT = ''' +SELECT LEAST(segmentsperround, segm+1) +FROM #db#.admin +''' + PREFIX = ''' SELECT shortname FROM #db#.admin ''' -- cgit v1.2.3