Skip to content

Commit

Permalink
Add Guide to Pharmacology (#19)
Browse files Browse the repository at this point in the history
* Add chemidplus

* Style fixes, add fmt params, raise ValueError on failure

* add Guide to Pharmacology

* Raise explicit Exception if version extraction from text fails

* Update guidetopharmacology.py

* Precompile regex

* Fail fast and decrease unnecessary indents

* Make constant available in case someone wants it

* Add new version type

Co-authored-by: Charles Tapley Hoyt <cthoyt@gmail.com>
  • Loading branch information
jsstevenson and cthoyt authored Oct 3, 2021
1 parent 3a9c486 commit e360ace
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/bioversions/sources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from .drugcentral import DrugCentralGetter
from .expasy import ExPASyGetter
from .flybase import FlybaseGetter
from .guidetopharmacology import GuideToPharmacologyGetter
from .homologene import HomoloGeneGetter
from .intact import IntActGetter
from .interpro import InterProGetter
Expand Down Expand Up @@ -95,6 +96,7 @@ def get_getters() -> List[Type[Getter]]:
NCItGetter,
RxNormGetter,
ChemIDplusGetter,
GuideToPharmacologyGetter,
OncoTreeGetter,
MOAlmanacGetter,
]
Expand Down
42 changes: 42 additions & 0 deletions src/bioversions/sources/guidetopharmacology.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# -*- coding: utf-8 -*-

"""A getter for GuideToPharmacology."""

import re
from datetime import datetime
from typing import Dict

from bioversions.utils import Getter, VersionType, get_soup

__all__ = [
"GuideToPharmacologyGetter",
]

URL = "https://www.guidetopharmacology.org/download.jsp"
RE = re.compile(r"^.*(\d{4}\.\d+).*(\d{2}\/\d{2}\/\d{2}).*$")


class GuideToPharmacologyGetter(Getter):
"""A getter for the IUPHAR Guide to Pharmacology."""

name = "Guide to Pharmacology"
homepage_fmt = "https://www.guidetopharmacology.org/DATA/public_iuphardb_v{version}.zip"
date_fmt = "%Y-%m-%d"
version_type = VersionType.year_minor

def get(self) -> Dict[str, str]:
"""Get the latest Guide to Pharmacology version number."""
soup = get_soup(URL)
text = soup.findAll("div", {"class": "contentboxfullhelp"})[4].div.ul.li.a.text
search = RE.search(text)
if not search:
raise ValueError(
"Unable to extract version/date from Guide to Pharmacology Downloads page."
)
grps = search.groups()
date = datetime.strftime(datetime.strptime(grps[1], "%d/%m/%y"), self.date_fmt)
return {"version": grps[0], "date": date}


if __name__ == "__main__":
GuideToPharmacologyGetter.print()
1 change: 1 addition & 0 deletions src/bioversions/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class VersionType(enum.Enum):
date = "CalVer (YYYY-MM-DD)"
month = "CalVer (YYYY-MM)"
year = "CalVer (YYYY)"
year_minor = "CalVer (YYYY.X)"
semver_minor = "SemVer (X.Y)"
sequential = "Sequential (X)"
daily = "Daily"
Expand Down

0 comments on commit e360ace

Please sign in to comment.