diff options
author | emkael <emkael@tlen.pl> | 2019-12-30 00:07:18 +0100 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2019-12-30 00:07:18 +0100 |
commit | e9f6263605cf0a4cf50c846796a7a027093a8045 (patch) | |
tree | aaa8f3b87a063013ac7522348af7e008de3040a8 | |
parent | 20a7ae6ec3575052727cc7e6d7b84a7cf8f2c85b (diff) |
Tournament results fetched from TC pages
-rw-r--r-- | jfr_playoff/tournamentinfo/__init__.py | 1 | ||||
-rw-r--r-- | jfr_playoff/tournamentinfo/tcjson.py | 38 |
2 files changed, 37 insertions, 2 deletions
diff --git a/jfr_playoff/tournamentinfo/__init__.py b/jfr_playoff/tournamentinfo/__init__.py index fa60d75..67cc8f6 100644 --- a/jfr_playoff/tournamentinfo/__init__.py +++ b/jfr_playoff/tournamentinfo/__init__.py @@ -20,7 +20,6 @@ class TournamentInfoClient(object): class TournamentInfo: - def __init__(self, settings, database): self.settings = settings from jfr_playoff.tournamentinfo.jfrdb import JFRDbTournamentInfo diff --git a/jfr_playoff/tournamentinfo/tcjson.py b/jfr_playoff/tournamentinfo/tcjson.py index ff5d6fa..3082cb0 100644 --- a/jfr_playoff/tournamentinfo/tcjson.py +++ b/jfr_playoff/tournamentinfo/tcjson.py @@ -1,5 +1,41 @@ +import json +import urlparse + +from jfr_playoff.remote import RemoteUrl as p_remote from jfr_playoff.tournamentinfo import TournamentInfoClient +FLAG_CDN_URL = 'https://cdn.tournamentcalculator.com/flags/' + class TCJsonTournamentInfo(TournamentInfoClient): - pass + def get_results_link(self, suffix): + return urlparse.urljoin(self.settings['link'], suffix) + + def is_finished(self): + settings_json = json.loads( + p_remote.fetch_raw(self.get_results_link('settings.json'))) + return (not settings_json['LiveResults']) \ + and (settings_json['LastPlayedRound'] > 0) \ + and (settings_json['LastPlayedSession'] > 0) + + def get_tournament_results(self): + results = [] + results_json = json.loads( + p_remote.fetch_raw(self.get_results_link('results.json'))) + for result in results_json['Results']: + participant = result['Participant'] + flag_url = None + flag = participant['_flag'] + if flag is not None: + flag_url = self.get_results_link( + flag['CustomFlagPath'] + if flag['IsCustom'] + else '%s/%s.png' % (FLAG_CDN_URL, flag['CountryNameCode'])) + results.append(( + result['ParticipantGroup'], result['Place'], + participant['_name'], participant['_shortName'], + flag_url)) + return [list(r[2:]) + [None] for r in sorted(results)] + + def get_exceptions(self, method): + return (TypeError, IndexError, KeyError, IOError, ValueError) |