-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
1 parent
3a9c486
commit e360ace
Showing
3 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters