Skip to content

Commit

Permalink
Background: Increase WDD timeout
Browse files Browse the repository at this point in the history
Also add constants for HTML request timeouts.
  • Loading branch information
UEWBot committed Jun 18, 2024
1 parent dd42a68 commit 0c41476
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions visualiser/tournament/background.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ class WikipediaBackground():
Get background on a player from wikipedia.
"""

# Timeout for retrieving wikipedia pages
TIMEOUT = 1.5

def __init__(self, name):
self.name = name

Expand All @@ -75,7 +78,7 @@ def titles(self):
"""
url = WIKIPEDIA_URL
try:
page = requests.get(url, timeout=1.5)
page = requests.get(url, timeout=self.TIMEOUT)
except requests.exceptions.Timeout:
return []
soup = BeautifulSoup(page.text)
Expand Down Expand Up @@ -127,6 +130,9 @@ class WDDBackground():
Get background on a player from the World Diplomacy Database.
"""

# timeout in seconds for read requests to WDD
TIMEOUT=3.0

def __init__(self, wdd_id):
self.wdd_id = wdd_id

Expand All @@ -140,7 +146,7 @@ def wdd_name(self):
page = requests.get(url,
params={'id_player': self.wdd_id},
allow_redirects=False,
timeout=2.5)
timeout=self.TIMEOUT)
except requests.exceptions.Timeout as e:
raise WDDNotAccessible from e
if page.status_code != requests.codes.ok:
Expand Down Expand Up @@ -183,7 +189,7 @@ def nationalities(self):
page = requests.get(url,
params={'id_player': self.wdd_id},
allow_redirects=False,
timeout=2.5)
timeout=self.TIMEOUT)
except requests.exceptions.Timeout as e:
raise WDDNotAccessible from e
if page.status_code != requests.codes.ok:
Expand Down Expand Up @@ -218,7 +224,7 @@ def finishes(self):
page = requests.get(url,
params={'id_player': self.wdd_id},
allow_redirects=False,
timeout=2.5)
timeout=self.TIMEOUT)
except requests.exceptions.Timeout as e:
raise WDDNotAccessible from e
if page.status_code != requests.codes.ok:
Expand Down Expand Up @@ -275,7 +281,7 @@ def tournaments(self):
page = requests.get(url,
params={'id_player': self.wdd_id},
allow_redirects=False,
timeout=2.5)
timeout=self.TIMEOUT)
except requests.exceptions.Timeout as e:
raise WDDNotAccessible from e
if page.status_code != requests.codes.ok:
Expand Down Expand Up @@ -345,7 +351,7 @@ def boards(self):
page = requests.get(url,
params={'id_player': self.wdd_id},
allow_redirects=False,
timeout=2.5)
timeout=self.TIMEOUT)
except requests.exceptions.Timeout as e:
raise WDDNotAccessible from e
if page.status_code != requests.codes.ok:
Expand Down Expand Up @@ -441,7 +447,7 @@ def awards(self):
page = requests.get(url,
params={'id_player': self.wdd_id},
allow_redirects=False,
timeout=2.5)
timeout=self.TIMEOUT)
except requests.exceptions.Timeout as e:
raise WDDNotAccessible from e
if page.status_code != requests.codes.ok:
Expand Down Expand Up @@ -513,7 +519,7 @@ def rankings(self):
page = requests.get(url,
params={'id_player': self.wdd_id},
allow_redirects=False,
timeout=2.5)
timeout=self.TIMEOUT)
except requests.exceptions.Timeout as e:
raise WDDNotAccessible from e
if page.status_code != requests.codes.ok:
Expand Down Expand Up @@ -545,7 +551,7 @@ def wpe_scores(self):
params={'id_ranking': 2,
'id_player': self.wdd_id},
allow_redirects=False,
timeout=2.5)
timeout=self.TIMEOUT)
except requests.exceptions.Timeout as e:
raise WDDNotAccessible from e
if page.status_code != requests.codes.ok:
Expand Down

0 comments on commit 0c41476

Please sign in to comment.