Skip to content
Snippets Groups Projects
Commit 69e8274a authored by gabriele-h's avatar gabriele-h
Browse files

Extract general functionality from get_single

parent 3b21673c
No related branches found
No related tags found
No related merge requests found
......@@ -77,14 +77,27 @@ class RecordRetriever:
:raises SruDiagnostics: if SRU returns an error
"""
sru_url = self._create_url(alma_query)
response = request.urlopen(sru_url).read()
sru_xml = fromstring(response)
self._raise_errors_single_records(sru_xml)
xml_list = self._extract_marc_xml(sru_xml, namespaces)
return xml_list[0]
def _create_url(self, alma_query: str) -> str:
self.url_query['startRecord'] = '0'
self.url_query['maximumRecords'] = '1'
self.url_query['query'] = alma_query
url_query_string = parse.urlencode(self.url_query)
sru_url = self.url_base + url_query_string
response = request.urlopen(sru_url).read()
sru_xml = fromstring(response)
return sru_url
def _raise_errors_single_records(self, sru_xml: Element):
namespaces = {
'srw': 'http://www.loc.gov/zing/srw/',
......@@ -112,9 +125,9 @@ class RecordRetriever:
sru_message = sru_xml.find(xpath, namespaces).text
raise SruDiagnostics(sru_message)
else:
def _extract_marc_xml(self, sru_xml, namespaces):
record_xpath = 'srw:records/srw:record//marc:record'
marc_xml = sru_xml.find(record_xpath, namespaces)
marc_xml = sru_xml.findall(record_xpath, namespaces)
return marc_xml
def by_marc_009(self, marc_009: str) -> Element:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment