Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Guide to Pharmacology #19

Merged
merged 11 commits into from
Oct 3, 2021
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