Refactor ABSConnector and its mock to improve library series retrieval and add file caching for library data
This commit is contained in:
parent
223bfbf6bc
commit
a81d277f17
3 changed files with 72 additions and 27 deletions
|
|
@ -1,6 +1,7 @@
|
|||
from ratelimit import limits
|
||||
import requests
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
class AudNexusConnector:
|
||||
|
|
@ -17,13 +18,22 @@ class AudNexusConnector:
|
|||
|
||||
|
||||
class AudNexusConnectorMock(AudNexusConnector):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
self.directory = "dumps/audnexus"
|
||||
if not os.path.exists(self.directory):
|
||||
os.makedirs(self.directory)
|
||||
|
||||
def get_book_from_asin(self, book_asin):
|
||||
path = f"{self.directory}/book_{book_asin}.json"
|
||||
|
||||
try:
|
||||
with open(f"dumps/book_{book_asin}.json", "r") as f:
|
||||
with open(path, "r") as f:
|
||||
data = json.load(f)
|
||||
return data
|
||||
except FileNotFoundError:
|
||||
data = AudNexusConnector.get_book_from_asin(self, book_asin)
|
||||
with open(f"dumps/book_{book_asin}.json", "w+") as f:
|
||||
with open(path, "w+") as f:
|
||||
json.dump(data, f, indent=4)
|
||||
return data
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue