1
0
Fork 0

Combines search formatter and parser function

The parser was extracting the list of search results from the json
object returned by the search endpoint, and the formatter was converting
an individual json entry into a SearchResult object. This just merged
them into one function, because they are never used separately.
This commit is contained in:
Mouse Reeve 2022-05-30 12:52:31 -07:00
parent 525e2a591d
commit 87fe984462
4 changed files with 60 additions and 85 deletions

View file

@ -52,11 +52,9 @@ class AbstractMinimalConnector(ABC):
"""Format the search results based on the formt of the query"""
# TODO: inventaire min confidence
parser = self.parse_search_data
formatter = self.format_search_result
if maybe_isbn(query):
parser = self.parse_isbn_search_data
formatter = self.format_isbn_search_result
return [formatter(doc) for doc in parser(data)[:10]]
return list(parser(data))[:10]
@abstractmethod
def get_or_create_book(self, remote_id):
@ -66,18 +64,10 @@ class AbstractMinimalConnector(ABC):
def parse_search_data(self, data):
"""turn the result json from a search into a list"""
@abstractmethod
def format_search_result(self, search_result):
"""create a SearchResult obj from json"""
@abstractmethod
def parse_isbn_search_data(self, data):
"""turn the result json from a search into a list"""
@abstractmethod
def format_isbn_search_result(self, search_result):
"""create a SearchResult obj from json"""
class AbstractConnector(AbstractMinimalConnector):
"""generic book data connector"""