├── .gitmodules ├── aidsinfo ├── __init__.py └── drug_info.py ├── README.md ├── test.py ├── LICENSE.md └── setup.py /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "aidsinfo/api"] 2 | path = aidsinfo/api 3 | url = git@github.com:codeforamerica/Python-API-Module.git 4 | -------------------------------------------------------------------------------- /aidsinfo/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """A Python wrapper for the available EPA API datasets.""" 4 | 5 | from drug_info import DrugInfo 6 | 7 | 8 | __all__ = [DrugInfo] 9 | -------------------------------------------------------------------------------- /aidsinfo/drug_info.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """Python wrapper for the AIDSinfo drug information API.""" 4 | 5 | from api import API 6 | 7 | class DrugInfo(API): 8 | """Python wrapper for the AIDSinfo drug information API.""" 9 | 10 | def __init__(self): 11 | super(DrugInfo, self).__init__() 12 | self.base_url = 'http://aidsinfo.nih.gov/DrugsNew/drug.aspx' 13 | self.output_format = 'xml' 14 | self.required_params = {'displayxml': 'true'} 15 | 16 | def search(self, name, **kwargs): 17 | """Search for a specific drug's information.""" 18 | kwargs.update({'name': name}) 19 | self.call_api(**kwargs) 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | AIDSinfo Python API Wrapper 2 | ====================== 3 | 4 | A Python wrapper for the AIDSinfo drug information API. 5 | 6 | AIDSinfo Documentation: http://www.aidsinfo.nih.gov/Other/rss.aspx 7 | 8 | 9 | Usage 10 | ----- 11 | 12 | ```python 13 | >>> from aidsinfo import DrugInfo 14 | >>> info = DrugInfo() 15 | >>> info.search('abacavir') 16 | {'abacavir': {'data': 'here'}} 17 | 18 | >>> info.search('combivir') 19 | {'combivir': {'data': 'here'}} 20 | 21 | >>> # You can also get back just the XML data. 22 | ... xml_data = info.search('combivir', output_format=None) 23 | ``` 24 | 25 | 26 | Copyright 27 | --------- 28 | 29 | Copyright (c) 2011 Code for America Laboratories. 30 | 31 | See LICENSE for details. 32 | -------------------------------------------------------------------------------- /test.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """Unit tests for the AIDSinfo drug information API.""" 4 | 5 | import unittest 6 | 7 | from mock import Mock 8 | 9 | from aidsinfo.api import api 10 | from aidsinfo import DrugInfo 11 | 12 | 13 | class TestDrugInfoSearchMethod(unittest.TestCase): 14 | 15 | def setUp(self): 16 | api.urlopen = Mock() 17 | api.xml2dict = Mock() 18 | 19 | def test_url_called_for_abacavir(self): 20 | info = DrugInfo() 21 | info.search('abacavir') 22 | expected_url = ('http://aidsinfo.nih.gov/DrugsNew/drug.aspx?' 23 | 'displayxml=true&name=abacavir') 24 | api.urlopen.assert_called_with(expected_url) 25 | 26 | def test_url_called_for_combivir(self): 27 | info = DrugInfo() 28 | info.search('combivir') 29 | expected_url = ('http://aidsinfo.nih.gov/DrugsNew/drug.aspx?' 30 | 'displayxml=true&name=combivir') 31 | api.urlopen.assert_called_with(expected_url) 32 | 33 | def test_xml_data_is_output(self): 34 | info = DrugInfo() 35 | info.search('combivir', output_format=None) 36 | self.assertFalse(api.xml2dict.called) 37 | 38 | 39 | if __name__ == '__main__': 40 | unittest.main() 41 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011, Code for America. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are met: 5 | 6 | Redistributions of source code must retain the above copyright notice, this 7 | list of conditions and the following disclaimer. Redistributions in binary 8 | form must reproduce the above copyright notice, this list of conditions and the 9 | following disclaimer in the documentation and/or other materials provided with 10 | the distribution. Neither the name of Code for America nor the names of its 11 | contributors may be used to endorse or promote products derived from this 12 | software without specific prior written permission. THIS SOFTWARE IS PROVIDED 13 | BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED 14 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 15 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 16 | EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 17 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 18 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 19 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 20 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 21 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | Author: Zach Williams, 4 | 5 | Copyright (c) 2011, Code for America. All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | 10 | Redistributions of source code must retain the above copyright notice, this 11 | list of conditions and the following disclaimer. Redistributions in binary form 12 | must reproduce the above copyright notice, this list of conditions and the 13 | following disclaimer in the documentation and/or other materials provided with 14 | the distribution. Neither the name of Code for America nor the names of its 15 | contributors may be used to endorse or promote products derived from this 16 | software without specific prior written permission. THIS SOFTWARE IS PROVIDED 17 | BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED 18 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 19 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 20 | EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 21 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 22 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 24 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 25 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | """ 28 | 29 | 30 | try: 31 | from setuptools import setup 32 | except ImportError: 33 | from distutils.core import setup 34 | 35 | 36 | long_description = """ 37 | AIDSinfo Python API Wrapper 38 | =========================== 39 | 40 | A Python wrapper for the AIDSinfo drug information API. 41 | 42 | AIDSinfo Documentation: http://www.aidsinfo.nih.gov/Other/rss.aspx 43 | 44 | 45 | Usage 46 | ----- 47 | 48 | >>> from aidsinfo import DrugInfo 49 | >>> info = DrugInfo() 50 | >>> info.search('abacavir') 51 | {'abacavir': {'data': 'here'}} 52 | 53 | >>> info.search('combivir') 54 | {'combivir': {'data': 'here'}} 55 | 56 | >>> # You can also get back just the XML data. 57 | ... xml_data = info.search('combivir', output_format=None) 58 | 59 | 60 | Copyright 61 | --------- 62 | 63 | Copyright (c) 2011 Code for America Laboratories. 64 | 65 | See LICENSE for details. 66 | """ 67 | 68 | setup(name="aidsinfo", 69 | version="1.1", 70 | description="A Python wrapper for the AIDSinfo drug information API.", 71 | long_description=long_description, 72 | keywords="aids, aids info, AIDSinfo, aidsinfo", 73 | author="Zach Williams", 74 | author_email="zach@codeforamerica.org", 75 | url="https://github.com/zachwill/fred", 76 | license="BSD", 77 | packages=['aidsinfo', 'aidsinfo.api', 'aidsinfo.api.xml2dict'], 78 | classifiers=['Development Status :: 5 - Production/Stable', 79 | 'Intended Audience :: Developers', 80 | 'Natural Language :: English', 81 | 'Operating System :: OS Independent', 82 | 'Programming Language :: Python :: 2', 83 | 'Topic :: Internet', 84 | 'Topic :: Internet :: WWW/HTTP', 85 | ], 86 | test_suite="test.py", 87 | tests_require=["mock", "Mock"]) 88 | --------------------------------------------------------------------------------