pydrugshortagesca
A minimal python wrapper around the drugshortagescanada.ca database API
Depends on requests module and will pass through exceptions from that library when they occur.
Installation
Install the package:
pip install pydrugshortagesca
You can then configure your drugshortagescanada.ca username and password in one of the following ways:
Create configuration file in ~/.config/pydrugshortagesca/config:
email="username@domain.com"
password="s3cr3t!"
Or, set the following environment variables:
export DSC_EMAIL="username@domain.com"
export DSC_PASSWORD="s3cr3t!"
You can test your installation by running the command pydrugshortagesca. You
should not be prompted for a username or password, and it should return some
results in JSON format.
Basic Usage
Interacting with the drugshortagescanada.ca database is done via the
api.Session object:
from pydrugshortagesca import api, export
import json
session = api.Session(email="name@domain.com", password="123456")
try:
session.login()
except Exception as e:
print("Error with log in", e)
print("Details:", session.response.content)
else:
# search() returns a batch of results.
# Use the `limit` and `offset` parameters to adjust which batch to return.
json_results = session.search(term="venlafaxine", offset=20)
print("Total results {}".format(json_results['total']))
# isearch() returns an iterator over all records returned by a search.
# This may make several requests to the database if needed.
results = session.isearch(term="venlafaxine", orderby='updated_date')
for rec in results:
print(rec['updated_date'],rec['en_drug_brand_name'],rec['drug_strength'])
# Custom filter functions can also be supplied
results = session.isearch(_filter=lambda x: x['drug_strength'] == '150.0MG',
term="venlafaxine", orderby='updated_date'):
for rec in results:
print(rec['updated_date'],rec['en_drug_brand_name'],rec['drug_strength'])
# The export module provides utility functions for exporting results in tabular form
csvfile = open('shortages.csv','w')
export.as_csv(session, csvfile, shortages=True, term="venlafaxine")
CLI
There is also a commandline interface. See pydrugshortagesca --help for details, but briefly:
$ pydrugshortagesca -p term venlafaxine --type shortages --fmt csv > shortages.csv
License
MIT
Contributing
Pull requests are very welcome!
Release files for pydrugshortagesca 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pydrugshortagesca-0.1.3.tar.gz | 6.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pydrugshortagesca-0.1.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 14.7 kB
Release files / pydrugshortagesca-0.1.3.tar.gz
| Download URL | pydrugshortagesca-0.1.3.tar.gz |
|---|---|
| Size | 6.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c650c827b81f7e1d6be0fb6597987bab2d84950b987f527cd0479f980f482434
|
|
BLAKE2b-256 checksum How to use checksums |
6fc3f3b5f6a0704e766be0ec282be5320f2a90682577c795f246b245b10ff9da
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.5 CPython/3.7.5 Linux/5.3.0-46-generic
|
Release files / pydrugshortagesca-0.1.3-py3-none-any.whl
| Download URL | pydrugshortagesca-0.1.3-py3-none-any.whl |
|---|---|
| Size | 8.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e404b377592e276d1262164c2360eea85ed2971096d8e80a66ba280282bc483a
|
|
BLAKE2b-256 checksum How to use checksums |
4bad726efcaff3cff57cc27c432a5a1cc45b5ecc3d7a0649727ec24f6a9069e8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.5 CPython/3.7.5 Linux/5.3.0-46-generic
|