summaryrefslogtreecommitdiff
path: root/jfr_playoff/matchinfo.py
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2018-02-20 11:54:58 +0100
committeremkael <emkael@tlen.pl>2018-02-20 11:54:58 +0100
commitce66c2114dc1d1a1067f35306bc1c6970ff35510 (patch)
treec87cf5a31958af64b026f31bd3383e011b737f24 /jfr_playoff/matchinfo.py
parentab371e10931e1c42877a0758cdcb2144e886850f (diff)
Cached remote URL fetching
Diffstat (limited to 'jfr_playoff/matchinfo.py')
-rw-r--r--jfr_playoff/matchinfo.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/jfr_playoff/matchinfo.py b/jfr_playoff/matchinfo.py
index 9f446cc..ca57718 100644
--- a/jfr_playoff/matchinfo.py
+++ b/jfr_playoff/matchinfo.py
@@ -1,4 +1,5 @@
import re
+import urllib
from urlparse import urljoin
import mysql
@@ -9,6 +10,7 @@ from jfr_playoff.dto import Match, Team
class MatchInfo:
matches = {}
+ url_cache = {}
def __init__(self, match_config, teams, database):
self.config = match_config
@@ -89,6 +91,11 @@ class MatchInfo:
teams[1].score -= row[2]
return teams
+ def __fetch_url(self, url):
+ if url not in MatchInfo.url_cache:
+ MatchInfo.url_cache[url] = urllib.urlopen(url).read()
+ return MatchInfo.url_cache[url]
+
def __get_config_teams(self, teams):
for i in range(0, 2):
match_teams = []