Add initial implementation of Audible Series Checker with API connectors and configuration
This commit is contained in:
commit
223bfbf6bc
10 changed files with 630 additions and 0 deletions
29
connectors/audnexus_connector.py
Normal file
29
connectors/audnexus_connector.py
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue