This is a very simple library for getting story data from the National Public Radio (NPR) API.
If you require Python < 2.6 then you will need the simplejson package.
If you require Python < 2.5 then you will need the cElementTree package.
>>> from kcrw.nprapi import StoryMapping >>> api = StoryMapping(MY_API_KEY) >>> result = api.query(ids=1) # The id 1 is a list of news stories >>> type(result) <type 'list'>
The StoryAPI class returns raw output from the NPR service in any of the available formats listed in:
>>> from kcrw.nprapi import StoryAPI >>> api = StoryAPI(MY_API_KEY, output_format='RSS') >>> result = api.query(ids=(1,'5',234)) >>> type(result) <type 'string'>
The query() method of both these classes takes a number of optional parameters, which are listed in:
and described in the NPR API input reference.
Additionally, this package provides an exception NPRError which is raised whenever the NPR API responds with an error message rather than data.