Skip to content

Commit

Permalink
Added retries to textpresso api + new paper evidence
Browse files Browse the repository at this point in the history
  • Loading branch information
valearna committed Jul 17, 2024
1 parent ae455fe commit c88888a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
21 changes: 12 additions & 9 deletions genedescriptions/api_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,18 @@ def get_textpresso_popularity(self, keyword: str):
data = data.encode('utf-8')
res = None
num_tries = 0
try:
num_tries += 1
req = urllib.request.Request(self.tpc_api_endpoint, data, headers={'Content-type': 'application/json',
'Accept': 'application/json'})
res = urllib.request.urlopen(req)
except HTTPException:
if num_tries > 5:
raise HTTPException
logger.debug("Sending request to Textpresso Central API")
while num_tries < 5:
try:
num_tries += 1
logger.debug("Sending request to Textpresso Central API")
req = urllib.request.Request(self.tpc_api_endpoint, data, headers={'Content-type': 'application/json',
'Accept': 'application/json'})
res = urllib.request.urlopen(req)
break
except Exception:
pass
if num_tries >= 5:
raise HTTPException
popularity = int(json.loads(res.read().decode('utf-8')))
self.tpc_cache[keyword] = popularity
return popularity
Expand Down
2 changes: 2 additions & 0 deletions genedescriptions/descriptions_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ def write_ace(self, file_path: str, curators_list: List[str], release_version: s
release_version + " version of WormBase\"\n")
outfile.write("Automated_description\t\"" + genedesc.description +
"\"\tPaper_evidence\t\"WBPaper00065943\"\n\n")
outfile.write("Automated_description\t\"" + genedesc.description +
"\"\tPaper_evidence\t\"WBPaper00067038\"\n\n")

def write_plain_text(self, file_path):
"""write the descriptions to a plain text file
Expand Down

0 comments on commit c88888a

Please sign in to comment.