Remove fedireads_key field
we have ID
This commit is contained in:
parent
fba1397444
commit
2fd7792f34
21 changed files with 65 additions and 70 deletions
|
@ -22,12 +22,13 @@ class AbstractConnector(ABC):
|
|||
self.max_query_count = info.max_query_count
|
||||
self.name = info.name
|
||||
self.local = info.local
|
||||
self.id = info.id
|
||||
|
||||
|
||||
def is_available(self):
|
||||
''' check if you're allowed to use this connector '''
|
||||
if self.connector.max_query_count is not None:
|
||||
if self.connector.query_count >= self.connector.max_query_count:
|
||||
if self.max_query_count is not None:
|
||||
if self.connector.query_count >= self.max_query_count:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
|
|
@ -9,6 +9,8 @@ from .abstract_connector import update_from_mappings, get_date
|
|||
|
||||
|
||||
class Connector(AbstractConnector):
|
||||
''' interact with other instances '''
|
||||
|
||||
def search(self, query):
|
||||
''' right now you can't search fedireads, but... '''
|
||||
resp = requests.get(
|
||||
|
@ -23,11 +25,11 @@ class Connector(AbstractConnector):
|
|||
return resp.json()
|
||||
|
||||
|
||||
def get_or_create_book(self, fedireads_key):
|
||||
def get_or_create_book(self, remote_id):
|
||||
''' pull up a book record by whatever means possible '''
|
||||
try:
|
||||
book = models.Book.objects.select_subclasses().get(
|
||||
fedireads_key=fedireads_key
|
||||
remote_id=remote_id
|
||||
)
|
||||
return book
|
||||
except ObjectDoesNotExist:
|
||||
|
@ -35,14 +37,14 @@ class Connector(AbstractConnector):
|
|||
# we can't load a book from a remote server, this is it
|
||||
return None
|
||||
# no book was found, so we start creating a new one
|
||||
book = models.Book(fedireads_key=fedireads_key)
|
||||
book = models.Book(remote_id=remote_id)
|
||||
|
||||
|
||||
def update_book(self, book):
|
||||
''' add remote data to a local book '''
|
||||
fedireads_key = book.fedireads_key
|
||||
remote_id = book.remote_id
|
||||
response = requests.get(
|
||||
'%s/%s' % (self.base_url, fedireads_key),
|
||||
'%s/%s' % (self.base_url, remote_id),
|
||||
headers={
|
||||
'Accept': 'application/activity+json; charset=utf-8',
|
||||
},
|
||||
|
@ -81,21 +83,21 @@ class Connector(AbstractConnector):
|
|||
return book
|
||||
|
||||
|
||||
def get_or_create_author(self, fedireads_key):
|
||||
def get_or_create_author(self, remote_id):
|
||||
''' load that author '''
|
||||
try:
|
||||
return models.Author.objects.get(fedireads_key=fedireads_key)
|
||||
return models.Author.objects.get(remote_id=remote_id)
|
||||
except ObjectDoesNotExist:
|
||||
pass
|
||||
|
||||
resp = requests.get('%s/authors/%s.json' % (self.url, fedireads_key))
|
||||
resp = requests.get('%s/authors/%s.json' % (self.url, remote_id))
|
||||
if not resp.ok:
|
||||
resp.raise_for_status()
|
||||
|
||||
data = resp.json()
|
||||
|
||||
# ingest a new author
|
||||
author = models.Author(fedireads_key=fedireads_key)
|
||||
author = models.Author(remote_id=remote_id)
|
||||
mappings = {
|
||||
'born': ('born', get_date),
|
||||
'died': ('died', get_date),
|
||||
|
|
|
@ -36,7 +36,7 @@ class Connector(AbstractConnector):
|
|||
search_results.append(
|
||||
SearchResult(
|
||||
book.title,
|
||||
book.fedireads_key,
|
||||
book.id,
|
||||
book.author_text,
|
||||
book.published_date.year if book.published_date else None,
|
||||
None
|
||||
|
@ -45,21 +45,21 @@ class Connector(AbstractConnector):
|
|||
return search_results
|
||||
|
||||
|
||||
def get_or_create_book(self, fedireads_key):
|
||||
def get_or_create_book(self, book_id):
|
||||
''' since this is querying its own data source, it can only
|
||||
get a book, not load one from an external source '''
|
||||
try:
|
||||
return models.Book.objects.select_subclasses().get(
|
||||
fedireads_key=fedireads_key
|
||||
id=book_id
|
||||
)
|
||||
except ObjectDoesNotExist:
|
||||
return None
|
||||
|
||||
|
||||
def get_or_create_author(self, fedireads_key):
|
||||
def get_or_create_author(self, author_id):
|
||||
''' load that author '''
|
||||
try:
|
||||
return models.Author.objects.get(fedreads_key=fedireads_key)
|
||||
return models.Author.objects.get(id=author_id)
|
||||
except ObjectDoesNotExist:
|
||||
pass
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue