Skip to content

Commit

Permalink
Fix DGI (#45)
Browse files Browse the repository at this point in the history
* Update to handle dgi v5 new homepage

* Remove unused import
  • Loading branch information
kkaris authored Aug 13, 2024
1 parent 7e701d3 commit 0ff199b
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/bioversions/sources/dgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@

"""A getter for the `Drug Gene Interaction Database (DGI-DB) <http://www.dgidb.org>`_."""

import os

import bs4
import dateutil.parser
import requests

from bioversions.utils import Getter, VersionType

DOWNLOADS_PAGE = "https://www.dgidb.org/downloads"
GITHUB_PAGE = "https://github.com/dgidb/dgidb-v5"


class DGIGetter(Getter):
Expand All @@ -21,14 +20,14 @@ class DGIGetter(Getter):

def get(self):
"""Get the latest DGI version number."""
res = requests.get(DOWNLOADS_PAGE)
soup = bs4.BeautifulSoup(res.content, parser="lxml", features="lxml")
cells = list(soup.select("table#tsv_downloads tbody tr:first-child td:nth-child(2) a"))
if 1 != len(cells):
res = requests.get(GITHUB_PAGE)
soup = bs4.BeautifulSoup(res.content)
time_tag = soup.find("relative-time")
if time_tag is None:
raise ValueError
cell = cells[0]
href = cell["href"]
version = os.path.dirname(os.path.relpath(href, "data/monthly_tsvs"))
datetime_str = time_tag.attrs["datetime"]
dt_obj = dateutil.parser.parse(datetime_str)
version = dt_obj.strftime(self.date_version_fmt)
return version


Expand Down

0 comments on commit 0ff199b

Please sign in to comment.