Module isbn
source code
This module provides functionality fetch information on a book (like
author and title) when given a isbn number.
Example usage:
import isbn
isbn.config() # read keys from keys.conf
result=isbn.fetch('978123456789X') # get info
At this moment it provides classes to retrieve information from Amazon
via ecs (you need a (free) license key), from libraries via
sru (at this moment: Library of Congress, Britisch Library
(Copac), and the dutch Koninklijke Bibliotheek) or from isbndb.com (you
need a (free) license key)via an ad-hoc webservice.
To implement this functionality an extensible hierarchy of classes is
provided. The base class is called SRU and most classes based on it merely override the
__init__() method to set a different url to retrieve the
information. The Amazon
class is slightly more complicated as it has to encrypt the url with a
key. Once a SRU derived
class in instantiated you can call the instances fetch()
method to try and retrieve the information. The result (either a
dictionary with entries or None) is stored in the result instance
variable.
Together with the SRU
class a number of ContentHandler derived classes are defined to interpret
the xml data that is returned.
For convenience the isbn module provides the following toplevel
functions:
-
fetch(isbnnumber) will try all sources defined
in this module (excluding the ones without proper keys)
-
awskeypair(id,key) set an amazon AWS keypair
-
isbndbdotcomkey(key) set an isbndb.com key
-
getproviders() get a list of classes
that can be used to fetch info
-
enable(klass) lets fetch() use this
class
-
disable(klass) prohibit fetch() using
this class
-
config(filename) configure AWS and/or
isbndb keys from a config file (default keys.conf)
|
|
DCHandler
Simple SAX content handler to process xml retrieved from an SRU
server.
|
|
|
COPACHandler
Simple SAX content handler to process xml retrieved from an SRU
server delivering xml using the mods schema and stores it in the
instance variable self.r.
|
|
|
AWSHandler
Simple SAX content handler to process xml retrieved from an AWS
server.
|
|
|
ISBNDBHandler
Simple SAX content handler to process xml retrieved from isbndb.com See isbn.fetch for
information about the contents.
|
|
|
SRUError
|
|
|
SRU
Base class for all classes that implement retrieval of book
information via a webservice.
|
|
|
Amazon
Fetch bookinformation from Amazon using ecs.
|
|
|
KoninklijkeBibliotheek
Fetch bookinformation from the dutch Koninklijke Bibliotheek using
sru.
|
|
|
BritishLibrary
Fetch bookinformation from the British Library (or actually Copac)
using sru.
|
|
|
LibraryOfCongress
Fetch bookinformation from the Library of Congress using
sru.
|
|
|
isbndbdotcom
Fetch bookinformation from the isbndb.com using a
webservice.
|
|
|
|
|
|
|
|
string.
If you pass in a 10 digit number the last digit is ignored. This
is to facilitate the conversion from an isbn-13 number (aka EAN code,
13 digits starting w. 978) to an isbn-10 number by simply chopping of
the first 3 digits and passing it to isbnchecksum().
Example:
isbn10 = isbnchecksum(isbn13[3:])
|
|
|
|
|
|
|
|
|
|
|
|
dict.
If a 13 digit isbn/ean code is given (i.e. a number starting w.
978), isbnfetch will try do find informtion first by trying
this 13 digit number then by using the derived 10 digit number.
The dictionary returned contains the following keys:
-
authors: a list of 1 or more authors
-
title: the book title
-
repository: the source of the info
It may contain extra information:
-
date: the publication date
-
publisher: the books publisher
-
binding: info on the physical form of the book, e.g. 'paperback'
-
value: the current listprice of the book
-
currency: the currency code, e,g, 'GBP''
-
cover: a file name containing a cover image
|
|
|
|
configfile(filename=None)
get/set the configfile used to retrieve keys from. |
source code
|
|
|
|
|
|
|
AWSId = 'No AWSId specified'
|
|
|
AWSKey = 'No AWSKey specified'
|
|
|
isbndbkey = 'No ISBNDB.com key specified'
|
|
|
_providers = {<class 'isbn.Amazon'>: False, <class 'isbn.Konin...
|
|
|
_configfile = 'keys.conf'
|
|
|
__package__ = None
|
|
get/set an Amazon AWS keypair and enable lookup via an Amazon class instance.
- Parameters:
Id (string.) - AWS Id, or None.
Key (string.) - AWS Key, or None.
- Returns:
- a tuple (AWSId,AWSKey) if Id == None, nothing otherwise.
|
|
get/set an isbndb.com key and enable lookup via an isbndbdotcom class
instance.
- Parameters:
key (string.) - AWS Key, or None.
- Returns:
- a string if key == None, nothing otherwise.
|
|
Calculate the checksum for an isbn-10 number.
- Parameters:
line (string.) - 9 or 10 digit number.
- Returns: string.
If you pass in a 10 digit number the last digit is ignored. This
is to facilitate the conversion from an isbn-13 number (aka EAN code,
13 digits starting w. 978) to an isbn-10 number by simply chopping of
the first 3 digits and passing it to isbnchecksum().
Example:
isbn10 = isbnchecksum(isbn13[3:])
- 10 digit isbnnumber.
|
|
Return a dictionary of possible providers of information.
Keys are the classes, values are True or False depending on whether
the will be used by isbn.fetch.
|
|
Indicate that class p should be used by isbn.fetch.
- Parameters:
p (SRU.) - an SRU derived class.
|
|
Indicate that class p should be NOT used by isbn.fetch.
- Parameters:
p (SRU.) - an SRU derived class.
|
|
Get bookinformation from a number of sources.
- Parameters:
isbn (string.) - a 10 or 13 digit isbn number.
- Returns: dict.
If a 13 digit isbn/ean code is given (i.e. a number starting w.
978), isbnfetch will try do find informtion first by trying
this 13 digit number then by using the derived 10 digit number.
The dictionary returned contains the following keys:
-
authors: a list of 1 or more authors
-
title: the book title
-
repository: the source of the info
It may contain extra information:
-
date: the publication date
-
publisher: the books publisher
-
binding: info on the physical form of the book, e.g. 'paperback'
-
value: the current listprice of the book
-
currency: the currency code, e,g, 'GBP''
-
cover: a file name containing a cover image
- a dictionary w. book information or None.
|
|
Read and set keys from a configfile.
Any ConfigParser.ConfigParser compatible
file (generally a .ini file) may be given as argument. The default is
keys.conf.
To be usefull it should contain the the section [keys].
Currently only Amazon AWS keypairs and isbndb.com keys are recognized.
The file may contain other sections, these are ignored.
Example config file:
[keys]
AWSId = "ABCDEFGHIJKLMNOP"
AWSKey = "gYGyGyGyHJDJHSGGSGFSHGDVfffDH"
isbndbkey = "HSUIUJSJ21"
|
_providers
- Value:
{<class 'isbn.Amazon'>: False,
<class 'isbn.KoninklijkeBibliotheek'>: True,
<class 'isbn.BritishLibrary'>: True,
<class 'isbn.LibraryOfCongress'>: True,
<class 'isbn.isbndbdotcom'>: False}
|
|