Aleph X-Service wrapper.
This module allows you to query Aleph’s X-Services module (Aleph server is defined by ALEPH_URL in settings.py).
There are two levels of abstraction:
You can use this functions to access Aleph:
searchInAleph(base, phrase, considerSimilar, field)
getDocumentIDs(aleph_search_result, [number_of_docs])
downloadMARCXML(doc_id, library)
downloadMARCOAI(doc_id, base)
Aleph works in strange way, that he won’t allow you to access desired information directly.
You have to create search request by calling searchInAleph() first, which will return dictionary with few imporant informations about session.
This dictionary can be later used as parameter to function getDocumentIDs(), which will give you list of DocumentID named tuples.
Named tuples are used, because to access your document, you won’t need just document ID number, but also library ID string.
Depending on your system, there may be just only one accessible library, or mutiple ones, and then you will be glad, that you get both of this informations together.
DocumentID can be used as parameter to downloadMARCXML().
Lets look at some code:
ids = getDocumentIDs(searchInAleph("nkc", "test", False, "wrd"))
for id_num, library in ids:
XML = downloadMARCXML(id_num, library)
# processDocument(XML)
So far, there are only getter wrappers:
getISBNsIDs()
getAuthorsBooksIDs()
getPublishersBooksIDs()
And counting functions (they are one request to aleph faster than just counting results from getters):
getISBNCount()
getAuthorsBooksCount()
getPublishersBooksCount()
List of valid bases can be obtained by calling _getListOfBases(), which returns list of strings.
There is also defined exception tree - see AlephException docstring for details.
Bases: exceptions.Exception
Exception tree:
- AlephException
|- InvalidAlephBaseException
|- InvalidAlephFieldException
|- LibraryNotFoundException
`- DocumentNotFoundException
Bases: edeposit.amqp.aleph.aleph.DocumentID
This structure is used to store pointer to document in aleph.
id of document
can be different for each document
default “nkc”, but really depends at what bases you have defined in your aleph
Download MARC OAI document with given doc_id from given (logical) base.
Funny part is, that some documents can be obtained only with this function in their full text.
Parameters: |
|
---|---|
Returns: | str – MARC XML unicode string. |
Raises: |
Download MARC XML document with given doc_id from given library.
Parameters: |
|
---|---|
Returns: | str – MARC XML unicode string. |
Raises: |
Get number of records in Aleph which match given author.
Parameters: |
|
---|---|
Returns: | int – Number of matching documents in Aleph. |
Get list of DocumentID objects of documents with given author.
Parameters: |
|
---|---|
Returns: | list – of DocumentID objects |
Get IDs, which can be used as parameters for other functions.
Parameters: |
|
---|---|
Returns: | list – DocumentID named tuples to given aleph_search_result. |
Raises: | AlephException – if Aleph returns unknown format of data |
Note
Returned DocumentID can be used as parameters to downloadMARCXML().
Get number of records in Aleph which match given isbn.
Parameters: |
|
---|---|
Returns: | int – Number of matching documents in Aleph. |
Get list of DocumentID objects of documents with given isbn.
Parameters: |
|
---|---|
Returns: | list – of DocumentID objects |
Get number of records in Aleph which match given publisher.
Parameters: |
|
---|---|
Returns: | int – Number of matching documents in Aleph. |
Get list of DocumentID objects of documents with given publisher.
Parameters: |
|
---|---|
Returns: | list – of DocumentID objects |
Send request to the aleph search engine.
Request itself is pretty useless, but it can be later used as parameter for getAlephRecords(), which can fetch records from Aleph.
Parameters: |
|
---|---|
Returns: | aleph_search_record, which is dictionary consisting from those fields – error (optional): present if there was some form of error
no_entries (int): number of entries that can be fetch from aleph
no_records (int): no idea what is this, but it is always >= than
no_entries
set_number (int): important - something like ID of your request
session-id (str): used to count users for licensing purposes
|
Example
Returned dict:
{
'session-id': 'YLI54HBQJESUTS678YYUNKEU4BNAUJDKA914GMF39J6K89VSCB',
'set_number': 36520,
'no_records': 1,
'no_entries': 1
}
Raises: |
|
---|