From f5c15f61592454e75aec384592f5d0c7f9ff1b07 Mon Sep 17 00:00:00 2001 From: emkael Date: Tue, 20 Feb 2018 11:59:47 +0100 Subject: Fetching running segment link from remote URL as a fallback to database --- jfr_playoff/matchinfo.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'jfr_playoff') diff --git a/jfr_playoff/matchinfo.py b/jfr_playoff/matchinfo.py index bd163af..5aa9d82 100644 --- a/jfr_playoff/matchinfo.py +++ b/jfr_playoff/matchinfo.py @@ -280,14 +280,26 @@ class MatchInfo: return '%s%st%d-%d.html' % ( prefix, round_no, self.config['table'], current_segment) + def __get_html_running_link(self): + row = self.__find_table_row(self.info.link) + running_link = row.select('td.bdcg a[href]') + if len(running_link) == 0: + raise ValueError('running link not found') + return urljoin(self.info.link, running_link[0]['href']) + def __determine_running_link(self): link_match = re.match(r'^(.*)runda(\d+)\.html$', self.info.link) if link_match: try: + if self.database is None: + raise KeyError('database not configured') self.info.link = self.__get_db_running_link( link_match.group(1), link_match.group(2)) except (mysql.connector.Error, TypeError, IndexError, KeyError): - pass + try: + self.info.link = self.__get_html_running_link() + except (TypeError, IndexError, KeyError, IOError, ValueError): + pass def set_phase_link(self, phase_link): if self.info.link is None: -- cgit v1.2.3