2021-03-08 16:49:10 +00:00
|
|
|
""" using another bookwyrm instance as a source of book data """
|
2023-07-28 15:43:32 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any, Iterator
|
|
|
|
|
2020-11-25 00:05:00 +00:00
|
|
|
from bookwyrm import activitypub, models
|
2021-09-16 18:30:04 +00:00
|
|
|
from bookwyrm.book_search import SearchResult
|
|
|
|
from .abstract_connector import AbstractMinimalConnector
|
2020-03-28 19:55:53 +00:00
|
|
|
|
|
|
|
|
2020-11-29 02:56:28 +00:00
|
|
|
class Connector(AbstractMinimalConnector):
|
2021-04-26 16:15:42 +00:00
|
|
|
"""this is basically just for search"""
|
2020-11-25 00:05:00 +00:00
|
|
|
|
2023-07-28 15:43:32 +00:00
|
|
|
def get_or_create_book(self, remote_id: str) -> models.Edition:
|
2021-04-28 22:19:24 +00:00
|
|
|
return activitypub.resolve_remote_id(remote_id, model=models.Edition)
|
2020-05-08 23:56:49 +00:00
|
|
|
|
2023-07-28 15:43:32 +00:00
|
|
|
def parse_search_data(
|
|
|
|
self, data: list[dict[str, Any]], min_confidence: float
|
|
|
|
) -> Iterator[SearchResult]:
|
2022-05-30 19:52:31 +00:00
|
|
|
for search_result in data:
|
|
|
|
search_result["connector"] = self
|
|
|
|
yield SearchResult(**search_result)
|
2021-03-01 20:09:21 +00:00
|
|
|
|
2023-07-28 15:43:32 +00:00
|
|
|
def parse_isbn_search_data(
|
|
|
|
self, data: list[dict[str, Any]]
|
|
|
|
) -> Iterator[SearchResult]:
|
2022-05-30 19:52:31 +00:00
|
|
|
for search_result in data:
|
2022-05-30 23:16:10 +00:00
|
|
|
search_result["connector"] = self
|
|
|
|
yield SearchResult(**search_result)
|