From ce66c2114dc1d1a1067f35306bc1c6970ff35510 Mon Sep 17 00:00:00 2001 From: emkael Date: Tue, 20 Feb 2018 11:54:58 +0100 Subject: Cached remote URL fetching --- jfr_playoff/matchinfo.py | 7 +++++++ 1 file changed, 7 insertions(+) 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 = [] -- cgit v1.2.3