#!/usr/bin/env python import pprint from nyplcollections import NYPLsearch # Create search object # Could also pass in a format of 'xml' if you want to use the raw_results # and require xml. Otherwise the search will return json in raw_results searchObj = NYPLsearch('dkh183x9ibxj4x8f') # Find captures based on uuid # Don't need to set this equal to anything, could also access results from # searchObj.results temp = searchObj.mods('acfeeb2d-7c5e-4ce7-e040-e00a180644aa') pp = pprint.PrettyPrinter(indent=4) pp.pprint(temp)
class TestNYPLsearch(unittest.TestCase): def setUp(self): self.nypl = NYPLsearch(KEY) def test_search(self): cats = self.nypl.search('cats') assert 200 == cats.status_code assert cats.request['perPage'] == 10 assert cats.results assert len(cats.results) assert cats.results[0].get('uuid') def test_next(self): cats = self.nypl.search('cats') mor_cats = next(cats) assert 200 == mor_cats.status_code def test_search_fields(self): maps = self.nypl.search('cartographic', field='typeOfResource') assert 200 == maps.status_code assert maps.results assert maps.results[0].get('uuid') def test_per_page(self): cats = self.nypl.search('cats', per_page=1) assert len(cats.results) == 1 def test_mods(self): uuid = '510d47dd-ab68-a3d9-e040-e00a18064a99' hades = '423990' mods = self.nypl.mods(uuid) assert 200 == mods.status_code identifiers = mods.results['identifier'] u = [i for i in identifiers if i['type'] == 'local_hades'] assert u[0]['$'] == hades assert mods.results['titleInfo'][1]['title']['$'] == u'Gowanus Bay - Brooklyn - 30th Street Pier.' def test_uuid(self): uuid = self.nypl.uuid('local_hades', '1017240') assert 200 == uuid.status_code assert 'ecaf7d80-c55f-012f-e3c7-58d385a7bc34' == uuid.results def test_captures(self): captures = self.nypl.captures('5fa75050-c6c7-012f-e24b-58d385a7bc34') assert 200 == captures.status_code assert 125 == captures.count assert type(captures.results) == list