summaryrefslogtreecommitdiff
path: root/jfr_playoff/tournamentinfo/tcjson.py
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2019-12-30 00:07:18 +0100
committeremkael <emkael@tlen.pl>2019-12-30 00:07:18 +0100
commite9f6263605cf0a4cf50c846796a7a027093a8045 (patch)
treeaaa8f3b87a063013ac7522348af7e008de3040a8 /jfr_playoff/tournamentinfo/tcjson.py
parent20a7ae6ec3575052727cc7e6d7b84a7cf8f2c85b (diff)
Tournament results fetched from TC pages
Diffstat (limited to 'jfr_playoff/tournamentinfo/tcjson.py')
-rw-r--r--jfr_playoff/tournamentinfo/tcjson.py38
1 files changed, 37 insertions, 1 deletions
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)