29 lines
905 B
Python
29 lines
905 B
Python
from ratelimit import limits
|
|
import requests
|
|
import json
|
|
|
|
|
|
class AudNexusConnector:
|
|
|
|
@limits(calls=100, period=60)
|
|
def request(self, url):
|
|
return requests.get(url, {"update": 0, "seedAuthors": 0})
|
|
|
|
def get_book_from_asin(self, book_asin):
|
|
endpoint = f"https://api.audnex.us/books/{book_asin}"
|
|
response = self.request(endpoint)
|
|
response.raise_for_status()
|
|
return response.json()
|
|
|
|
|
|
class AudNexusConnectorMock(AudNexusConnector):
|
|
def get_book_from_asin(self, book_asin):
|
|
try:
|
|
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(f"dumps/book_{book_asin}.json", "w+") as f:
|
|
json.dump(data, f, indent=4)
|
|
return data
|