forked from mirrors/bookwyrm
Adds isbn search
This commit is contained in:
parent
0a41503572
commit
f4800307b4
4 changed files with 84 additions and 6 deletions
|
@ -81,19 +81,31 @@ class Connector(AbstractConnector):
|
|||
)
|
||||
return SearchResult(
|
||||
title=search_result.get("label"),
|
||||
key="{:s}?action=by-uris&uris={:s}".format(
|
||||
self.books_url, search_result.get("uri")
|
||||
),
|
||||
key=self.get_remote_id(search_result.get("uri")),
|
||||
view_link="{:s}{:s}".format(self.base_url, search_result.get("uri")),
|
||||
cover=cover,
|
||||
connector=self,
|
||||
)
|
||||
|
||||
def parse_isbn_search_data(self, data):
|
||||
"""boop doop"""
|
||||
"""got some daaaata"""
|
||||
results = data.get('entities')
|
||||
if not results:
|
||||
return []
|
||||
return list(results.values())
|
||||
|
||||
def format_isbn_search_result(self, search_result):
|
||||
"""beep bloop"""
|
||||
"""totally different format than a regular search result"""
|
||||
title = search_result.get("claims", {}).get("wdt:P1476", [])
|
||||
if not title:
|
||||
return None
|
||||
return SearchResult(
|
||||
title=title[0],
|
||||
key=self.get_remote_id(search_result.get("uri")),
|
||||
view_link="{:s}{:s}".format(self.base_url, search_result.get("uri")),
|
||||
cover=self.get_cover_url(search_result.get("image")),
|
||||
connector=self
|
||||
)
|
||||
|
||||
def is_work_data(self, data):
|
||||
return data.get("type") == "work"
|
||||
|
|
|
@ -136,3 +136,22 @@ class Inventaire(TestCase):
|
|||
]
|
||||
result = self.connector.resolve_keys(keys)
|
||||
self.assertEqual(result, ["epistolary novel", "crime novel"])
|
||||
|
||||
def test_isbn_search(self):
|
||||
""" another search type """
|
||||
search_file = pathlib.Path(__file__).parent.joinpath(
|
||||
"../data/inventaire_isbn_search.json"
|
||||
)
|
||||
search_results = json.loads(search_file.read_bytes())
|
||||
|
||||
results = self.connector.parse_isbn_search_data(search_results)
|
||||
formatted = self.connector.format_isbn_search_result(results[0])
|
||||
|
||||
self.assertEqual(formatted.title, "L'homme aux cercles bleus")
|
||||
self.assertEqual(
|
||||
formatted.key, "https://inventaire.io?action=by-uris&uris=isbn:9782290349229"
|
||||
)
|
||||
self.assertEqual(
|
||||
formatted.cover,
|
||||
"https://covers.inventaire.io/img/entities/12345",
|
||||
)
|
||||
|
|
48
bookwyrm/tests/data/inventaire_isbn_search.json
Normal file
48
bookwyrm/tests/data/inventaire_isbn_search.json
Normal file
|
@ -0,0 +1,48 @@
|
|||
{
|
||||
"entities": {
|
||||
"isbn:9782290349229": {
|
||||
"_id": "d59e3e64f92c6340fbb10c5dcf7c0abf",
|
||||
"_rev": "3-079ed51158a001dc74caafb21cff1c22",
|
||||
"type": "edition",
|
||||
"labels": {},
|
||||
"claims": {
|
||||
"wdt:P31": [
|
||||
"wd:Q3331189"
|
||||
],
|
||||
"wdt:P212": [
|
||||
"978-2-290-34922-9"
|
||||
],
|
||||
"wdt:P957": [
|
||||
"2-290-34922-4"
|
||||
],
|
||||
"wdt:P407": [
|
||||
"wd:Q150"
|
||||
],
|
||||
"wdt:P1476": [
|
||||
"L'homme aux cercles bleus"
|
||||
],
|
||||
"wdt:P629": [
|
||||
"wd:Q3203603"
|
||||
],
|
||||
"wdt:P123": [
|
||||
"wd:Q3156592"
|
||||
],
|
||||
"invp:P2": [
|
||||
"57883743aa7c6ad25885a63e6e94349ec4f71562"
|
||||
],
|
||||
"wdt:P577": [
|
||||
"2005-05-01"
|
||||
]
|
||||
},
|
||||
"created": 1485023383338,
|
||||
"updated": 1609171008418,
|
||||
"version": 5,
|
||||
"uri": "isbn:9782290349229",
|
||||
"originalLang": "fr",
|
||||
"image": {
|
||||
"url": "/img/entities/12345"
|
||||
}
|
||||
}
|
||||
},
|
||||
"redirects": {}
|
||||
}
|
|
@ -156,7 +156,6 @@ class EditBook(View):
|
|||
),
|
||||
}
|
||||
)
|
||||
print(data["author_matches"])
|
||||
|
||||
# we're creating a new book
|
||||
if not book:
|
||||
|
|
Loading…
Reference in a new issue