Compare commits
No commits in common. "503ffd0930c7c545a38b6c2bf59fab52a7c9c675" and "223bfbf6bc58d8557ee3a0c4fbda98a95ddeec0f" have entirely different histories.
503ffd0930
...
223bfbf6bc
5 changed files with 33 additions and 89 deletions
|
|
@ -1,6 +1,5 @@
|
|||
import requests
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
class ABSConnector:
|
||||
|
|
@ -16,8 +15,11 @@ class ABSConnector:
|
|||
data = response.json()
|
||||
return data["libraries"]
|
||||
|
||||
def _get_library_page(self, library_id, page=0, page_size=100):
|
||||
def get_series_by_library_id(self, library_id, page_size=100):
|
||||
endpoint = f"{self.abs_url}/api/libraries/{library_id}/series"
|
||||
page = 0
|
||||
|
||||
while True:
|
||||
response = self.requests.get(
|
||||
endpoint,
|
||||
params={
|
||||
|
|
@ -28,13 +30,7 @@ class ABSConnector:
|
|||
},
|
||||
)
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
|
||||
def get_series_by_library_id(self, library_id, page_size=100):
|
||||
page = 0
|
||||
|
||||
while True:
|
||||
data = self.__get_library_page(library_id, page, page_size)
|
||||
data = response.json()
|
||||
|
||||
yield from data["results"]
|
||||
|
||||
|
|
@ -45,39 +41,17 @@ class ABSConnector:
|
|||
|
||||
|
||||
class ABSConnectorMock(ABSConnector):
|
||||
def __init__(self, abs_url, token=None):
|
||||
super().__init__(abs_url, token)
|
||||
|
||||
self.directory = "dumps/abs"
|
||||
if not os.path.exists(self.directory):
|
||||
os.makedirs(self.directory)
|
||||
|
||||
def get_library_ids(self):
|
||||
path = f"{self.directory}/libraries.json"
|
||||
|
||||
try:
|
||||
with open(path, "r") as f:
|
||||
with open("dumps/libraries.json", "r") as f:
|
||||
data = json.load(f)
|
||||
return data["libraries"]
|
||||
except FileNotFoundError:
|
||||
data = ABSConnector.get_library_ids(self)
|
||||
with open(path, "w+") as f:
|
||||
json.dump({"libraries": data}, f, indent=4)
|
||||
return data
|
||||
|
||||
def get_series_by_library_id(self, library_id, page_size=100):
|
||||
page = 0
|
||||
|
||||
while True:
|
||||
path = f"{self.directory}/library_{library_id}.page_{page}.json"
|
||||
|
||||
try:
|
||||
with open(path, "r") as f:
|
||||
with open(f"dumps/library_{library_id}.page{page}.json", "r") as f:
|
||||
data = json.load(f)
|
||||
except FileNotFoundError:
|
||||
data = ABSConnector._get_library_page(self, library_id, page, page_size)
|
||||
with open(path, "w+") as f:
|
||||
json.dump(data, f, indent=4)
|
||||
|
||||
yield from data["results"]
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
from getpass import getpass
|
||||
import os
|
||||
import audible
|
||||
import json
|
||||
import os
|
||||
from getpass import getpass
|
||||
|
||||
|
||||
class AudibleConnector:
|
||||
|
|
@ -44,22 +44,13 @@ 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(path, "r") as f:
|
||||
with open(f"dumps/products_{asin}.json", "r") as f:
|
||||
data = json.load(f)
|
||||
return data["product"]
|
||||
except FileNotFoundError:
|
||||
data = AudibleConnector.get_produce_from_asin(self, asin)
|
||||
with open(path, "w+") as f:
|
||||
with open(f"dumps/products_{asin}.json", "w+") as f:
|
||||
json.dump({"product": data}, f, indent=4)
|
||||
return data
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
from ratelimit import limits
|
||||
import requests
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
class AudNexusConnector:
|
||||
|
|
@ -18,22 +17,13 @@ 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(path, "r") as f:
|
||||
with open(f"dumps/book_{book_asin}.json", "r") as f:
|
||||
data = json.load(f)
|
||||
return data
|
||||
except FileNotFoundError:
|
||||
data = AudNexusConnector.get_book_from_asin(self, book_asin)
|
||||
with open(path, "w+") as f:
|
||||
with open(f"dumps/book_{book_asin}.json", "w+") as f:
|
||||
json.dump(data, f, indent=4)
|
||||
return data
|
||||
|
|
|
|||
15
main.py
15
main.py
|
|
@ -1,11 +1,11 @@
|
|||
import connectors
|
||||
import argparse
|
||||
import logging
|
||||
import config
|
||||
|
||||
logging.basicConfig(
|
||||
filename="log",
|
||||
filemode="w",
|
||||
level=logging.INFO,
|
||||
format="%(levelname)s - %(message)s",
|
||||
)
|
||||
|
||||
|
|
@ -198,21 +198,10 @@ if __name__ == "__main__":
|
|||
logging.getLogger("urllib3").setLevel(logging.WARNING)
|
||||
logging.getLogger("httpcore").setLevel(logging.WARNING)
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("-d", "--dev", action="store_true")
|
||||
parser.add_argument("-v", "--verbose", action="store_true")
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.dev:
|
||||
abs = connectors.ABSConnectorMock(config.ABS_API_URL, config.ABS_API_TOKEN)
|
||||
audible = connectors.AudibleConnectorMock(config.AUDIBLE_AUTH_FILE)
|
||||
audnexus = connectors.AudNexusConnectorMock()
|
||||
else:
|
||||
abs = connectors.ABSConnector(config.ABS_API_URL, config.ABS_API_TOKEN)
|
||||
audible = connectors.AudibleConnector(config.AUDIBLE_AUTH_FILE)
|
||||
audnexus = connectors.AudNexusConnector()
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
logger.setLevel(logging.DEBUG if args.verbose else logging.INFO)
|
||||
main()
|
||||
|
|
|
|||
BIN
requirements.txt
BIN
requirements.txt
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue