summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichał Klichowicz <emkael@tlen.pl>2026-09-10 12:57:35 +0200
committerMichał Klichowicz <emkael@tlen.pl>2026-09-10 12:57:35 +0200
commit13906ea84e04ae3b0e28c4e3576fe93278d7eecb (patch)
tree0e12c020e3cf629ead5a9eba7303630e8d637f1e
parente539fa58a5329ae0e6c9ccb32e217619a55f3130 (diff)
TC JSON files can be served GZIP-ed, support it transparently (as long as remote server sets proper Content-Type headers)gzipped-tcjson
-rw-r--r--jfr_playoff/data/match/tcjson.py8
-rw-r--r--jfr_playoff/data/tournament/tcjson.py10
-rw-r--r--jfr_playoff/remote.py12
3 files changed, 24 insertions, 6 deletions
diff --git a/jfr_playoff/data/match/tcjson.py b/jfr_playoff/data/match/tcjson.py
index 60f6f81..470ac91 100644
--- a/jfr_playoff/data/match/tcjson.py
+++ b/jfr_playoff/data/match/tcjson.py
@@ -41,7 +41,9 @@ class TCJsonMatchInfo(MatchInfoClient):
round_results = json.loads(
p_remote.fetch_raw(
self._get_results_link(
- 'o%d-%d.json' % (session_no, round_no))))
+ 'o%d-%d.json' % (session_no, round_no)),
+ gzip_fallback = True
+ ))
table_id = str(table_no)
for result in round_results['Results']:
if result['Table'] == table_id:
@@ -103,7 +105,9 @@ class TCJsonMatchInfo(MatchInfoClient):
def running_link(self):
settings = json.loads(p_remote.fetch_raw(
- self._get_results_link('settings.json')))
+ self._get_results_link('settings.json'),
+ gzip_fallback=True
+ ))
if settings['ShowOnlyResults']:
PlayoffLogger.get('match.tcjson').info(
'ShowOnlyResults active, no running segment link available')
diff --git a/jfr_playoff/data/tournament/tcjson.py b/jfr_playoff/data/tournament/tcjson.py
index c84c27f..c84a864 100644
--- a/jfr_playoff/data/tournament/tcjson.py
+++ b/jfr_playoff/data/tournament/tcjson.py
@@ -28,7 +28,10 @@ class TCJsonTournamentInfo(TournamentInfoClient):
def is_finished(self):
settings_json = json.loads(
- p_remote.fetch_raw(self.get_results_link('settings.json')))
+ p_remote.fetch_raw(
+ self.get_results_link('settings.json'),
+ gzip_fallback=True
+ ))
live_results = settings_json['LiveResults']
last_round = settings_json['LastPlayedRound']
last_session = settings_json['LastPlayedSession']
@@ -42,7 +45,10 @@ class TCJsonTournamentInfo(TournamentInfoClient):
def get_tournament_results(self):
results = []
results_json = json.loads(
- p_remote.fetch_raw(self.get_results_link('results.json')))
+ p_remote.fetch_raw(
+ self.get_results_link('results.json'),
+ gzip_fallback=True
+ ))
participant_groups = []
for result in results_json['Results']:
group = result['ParticipantGroup']
diff --git a/jfr_playoff/remote.py b/jfr_playoff/remote.py
index 8f6f78f..54031a8 100644
--- a/jfr_playoff/remote.py
+++ b/jfr_playoff/remote.py
@@ -1,4 +1,4 @@
-import re
+import re, urlparse
import requests
@@ -10,11 +10,19 @@ class RemoteUrl:
url_cache = {}
@classmethod
- def fetch_raw(cls, url):
+ def fetch_raw(cls, url, gzip_fallback=False):
PlayoffLogger.get('remote').info(
'fetching content for: %s', url)
if url not in cls.url_cache:
request = requests.get(url)
+ if request.status_code == 404 and gzip_fallback:
+ old_url = urlparse.urlparse(url)
+ new_url = old_url._replace(path=old_url.path+'.gz')
+ new_url = urlparse.urlunparse(new_url)
+ PlayoffLogger.get('remote').info(
+ 'URL %s not found, trying GZIP variant %s',
+ url, new_url)
+ request = requests.get(url)
encoding_match = re.search(
'content=".*;( )?charset=(.*?)"',
request.content, re.IGNORECASE)