Skip to content

Commit d0673e0

Browse files
committed
Added API key support
1 parent fdbf31c commit d0673e0

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

example.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env python3
2-
# -*- coding: utf-8 -*-
32

43
import os
54
import sys
@@ -10,6 +9,7 @@
109

1110
oai_handler = oai
1211
oai_handler.current_set = "ANP"
12+
oai_handler.set_key("")
1313

1414
response = sru.search("karel AND reve AND hooftprijs", "ANP")
1515
print ("Number of records: %i" % response.sru.nr_of_records)

kb/nl/api/oai.py

+20-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from kb.nl.collections import SETS
55
from kb.nl.helpers import etree
66

7-
OAI_BASEURL = 'http://services.kb.nl/mdo/oai'
87

98

109
class oai:
@@ -34,7 +33,10 @@ class oai:
3433
current_set = False
3534
oai_sets = SETS
3635
resumptiontoken = False
36+
3737
DEBUG = False
38+
KEY = False
39+
OAI_BASEURL = 'http://services.kb.nl/mdo/oai'
3840

3941
def __init__(self, current_set=False):
4042
if current_set:
@@ -46,6 +48,21 @@ def list_sets(self):
4648
"""
4749
return sorted(self.oai_sets.keys())
4850

51+
def set_key(self, key):
52+
"""
53+
Sets the key for the OAI-session,
54+
some parts of the collection are protected.
55+
to request a key see this page:
56+
57+
https://www.kb.nl/en/resources-research-guides/data-services-apis
58+
59+
:param key: OAI key
60+
"""
61+
if not self.KEY:
62+
self.KEY = key
63+
self.OAI_BASEURL += "/" + key
64+
return
65+
4966
def list_records(self, setname, resumptiontoken=False):
5067
"""
5168
Retrieves a list of records from the OAI server,
@@ -64,7 +81,7 @@ def list_records(self, setname, resumptiontoken=False):
6481
if not resumptiontoken:
6582
self.resumptiontoken = False
6683

67-
url = OAI_BASEURL
84+
url = self.OAI_BASEURL
6885
url += '?verb=ListRecords'
6986
url += '&metadataPrefix=' + self.oai_sets[setname]['metadataPrefix']
7087
url += '&set=' + self.oai_sets[setname]['setname']
@@ -110,7 +127,7 @@ def get(self, identifier):
110127
identifier = 'BYVANCK:' + identifier
111128
identifier = identifier.replace('BYVANCK', 'ByvanckB')
112129

113-
url = OAI_BASEURL
130+
url = self.OAI_BASEURL
114131
url += '?verb=GetRecord'
115132
url += '&identifier=' + identifier
116133

setup.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
setup(
44
author="WillemJan Faber",
5-
5+
author_email="[email protected]",
66
name='kb',
77
url="https://github.com/KBNLresearch/KB-python-API",
88
description='Access to National Library of the Netherlands datasets',
9-
version='0.1.7',
9+
version='0.1.9',
1010
packages=['kb.nl.api', 'kb.nl.helpers', 'kb', 'kb.nl', 'kb.nl.collections'],
1111
license='GNU General Public License',
1212
install_requires=['lxml>=2.3', 'requests'],

0 commit comments

Comments
 (0)