Refactor ABSConnector and its mock to improve library series retrieval and add file caching for library data

This commit is contained in:
Yunn Xairou 2025-08-30 12:11:50 +02:00
parent 223bfbf6bc
commit a81d277f17
3 changed files with 72 additions and 27 deletions

View file

@ -1,7 +1,7 @@
import os
from getpass import getpass
import audible
import json
from getpass import getpass
import os
class AudibleConnector:
@ -44,13 +44,22 @@ class AudibleConnector:
class AudibleConnectorMock(AudibleConnector):
def __init__(self, authFile):
super().__init__(authFile)
self.directory = "dumps/audible"
if not os.path.exists(self.directory):
os.makedirs(self.directory)
def get_produce_from_asin(self, asin):
path = f"{self.directory}/products_{asin}.json"
try:
with open(f"dumps/products_{asin}.json", "r") as f:
with open(path, "r") as f:
data = json.load(f)
return data["product"]
except FileNotFoundError:
data = AudibleConnector.get_produce_from_asin(self, asin)
with open(f"dumps/products_{asin}.json", "w+") as f:
with open(path, "w+") as f:
json.dump({"product": data}, f, indent=4)
return data