Skip to content

Commit 819e3b6

Browse files
committed
Bumped version, pep8
1 parent 6cd2c1d commit 819e3b6

File tree

4 files changed

+30
-31
lines changed

4 files changed

+30
-31
lines changed

kb/nl/api/oai.py

+16-14
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99

1010
class oai():
11+
1112
"""
1213
OAI interface to the National Library of the Netherlands.
1314
For more information on the OAI protocol, visit:
@@ -35,7 +36,7 @@ class oai():
3536
resumptiontoken = False
3637
DEBUG = False
3738

38-
def __init__(self, current_set = False):
39+
def __init__(self, current_set=False):
3940
if current_set:
4041
self.current_set = current_set
4142

@@ -130,6 +131,7 @@ def get(self, identifier):
130131

131132

132133
class records():
134+
133135
"""
134136
Class for parsing xml output from OAI server,
135137
to usable objects.
@@ -162,12 +164,14 @@ def deleted_identifiers(self):
162164
deleted = []
163165
for item in self.records_data[2]:
164166
if item.tag.endswith('record'):
165-
if item[0].tag.endswith('header') and item[0].attrib.get('status') == 'deleted':
167+
if item[0].tag.endswith('header') and \
168+
item[0].attrib.get('status') == 'deleted':
166169
deleted.append(item[0][0].text)
167170
return deleted
168171

169172

170173
class record():
174+
171175
"""
172176
Class for parsing XML output from OAI server,
173177
to more human readable form. This class
@@ -265,7 +269,8 @@ def alto(self):
265269
sys.stdout.write(alto_url + " ")
266270

267271
if not response.status_code == 200:
268-
raise Exception('Error while getting data from %s' % alto_url)
272+
raise Exception(
273+
'Error while getting data from %s' % alto_url)
269274

270275
alto_list.append(response.text)
271276

@@ -282,18 +287,15 @@ def ocr(self):
282287
if item.attrib and \
283288
item.attrib.get('ref') and \
284289
item.attrib['ref'].lower().endswith(':ocr'):
290+
url = item.attrib['ref']
291+
if self.DEBUG:
292+
sys.stdout.write(url)
285293

286-
url = item.attrib['ref']
287-
288-
if self.DEBUG:
289-
sys.stdout.write(url)
290-
291-
response = requests.get(url)
292-
if not response.status_code == 200:
293-
return False
294-
return response.text
295-
return False
296-
294+
response = requests.get(url)
295+
if not response.status_code == 200:
296+
return False
297+
return response.text
298+
return False
297299

298300
@property
299301
def image(self):

kb/nl/api/sru.py

+12-15
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
import requests
33
import urllib
44

5+
try:
6+
from urllib import quote # Python 2.X
7+
except ImportError:
8+
from urllib.parse import quote # Python 3+
9+
510
from kb.nl.collections import SETS
611
from kb.nl.helpers import etree
712

@@ -17,15 +22,6 @@ class response():
1722
def __init__(self, record_data, sru):
1823
self.record_data = record_data
1924
self.sru = sru
20-
21-
"""
22-
@property
23-
def identifiers(self):
24-
id = [i.text.split('=')[1] for i in self.record_data.iter() if
25-
i.tag.endswith('identifier') and
26-
i.text.find(':') > -1]
27-
return id
28-
"""
2925

3026
@property
3127
def records(self):
@@ -37,23 +33,24 @@ def records(self):
3733
namespaces=ns)[0]
3834
return(record(record_data, self.sru))
3935

40-
# TODO: distinguish by xsi:type
36+
# TODO: distinguish by xsi:type
4137
@property
4238
def identifiers(self):
43-
result = [r.text.replace('http://resolver.kb.nl/resolve?urn=', '') for r in self.record_data.iter() if
39+
baseurl = 'http://resolver.kb.nl/resolve?urn='
40+
result = [r.text.replace(baseurl, '') for r in self.record_data.iter() if
4441
r.tag.endswith('identifier') and r.text.find(':') > -1]
4542
return result
4643

4744
@property
4845
def types(self):
4946
return [r.text for r in self.record_data.iter() if
5047
r.tag.endswith('type')]
51-
48+
5249
@property
5350
def languages(self):
5451
return [r.text for r in self.record_data.iter() if
5552
r.tag.endswith('language')]
56-
53+
5754
@property
5855
def dates(self):
5956
return [r.text for r in self.record_data.iter() if
@@ -137,7 +134,7 @@ def search(self, query, collection=False,
137134
startrecord=1, maximumrecords=1, recordschema=False):
138135

139136
self.maximumrecords = maximumrecords
140-
self.query = urllib.quote_plus(query)
137+
self.query = quote(query)
141138
self.startrecord = startrecord
142139

143140
if collection not in self.sru_collections:
@@ -160,7 +157,7 @@ def search(self, query, collection=False,
160157

161158
self.nr_of_records = int(nr_of_records)
162159

163-
if nr_of_records > 0:
160+
if self.nr_of_records > 0:
164161
return response(record_data, self)
165162

166163
return False

kb/nl/collections/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@
2828
'metadataPrefix': 'dcx',
2929
'recordschema': 'dcx',
3030
'setname': 'ggc',
31-
'time_period': [1937, 2016]}} # No idea what to use here?
31+
'time_period': [1937, 2016]}}

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
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.6',
9+
version='0.1.7',
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)