Skip to content

Commit

Permalink
CU-8692kpchc Fix for Rosalind link not working (#342)
Browse files Browse the repository at this point in the history
* CU-8692kpchc Add the 403 exception to vocab downloader

* CU-8692kpchc Add the new vocab download link
  • Loading branch information
mart-r committed Sep 22, 2023
1 parent ef4e752 commit c67995c
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions tests/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ async def __call__(self, *args, **kwargs):
</body></html>
"""

ERROR_403 = b"""<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access this resource.</p>
</body></html>
"""

SIMPLE_WORDS = """house 34444 0.3232 0.123213 1.231231
dog 14444 0.76762 0.76767 1.45454"""

Expand All @@ -45,7 +54,7 @@ def generate_simple_vocab():


class VocabDownloader:
url = 'https://medcat.rosalind.kcl.ac.uk/media/vocab.dat'
url = 'https://cogstack-medcat-example-models.s3.eu-west-2.amazonaws.com/medcat-example-models/vocab.dat'
vocab_path = "./tmp_vocab.dat"
_has_simple = False

Expand All @@ -54,6 +63,8 @@ def is_valid(self):
content = f.read()
if content == ERROR_503:
return False
if content == ERROR_403:
return False
v = Vocab.load(self.vocab_path)
if len(v.vocab) == 2: # simple one
self._has_simple = True
Expand All @@ -64,7 +75,7 @@ def check_or_download(self):
if os.path.exists(self.vocab_path) and self.is_valid():
return
tmp = requests.get(self.url)
if tmp.content == ERROR_503:
if tmp.content == ERROR_503 or tmp.content == ERROR_403:
print('Rosalind server unavailable')
if self._has_simple:
print('Local simple vocab already present')
Expand Down

0 comments on commit c67995c

Please sign in to comment.