feat: create client in constructor after authentication
This commit is contained in:
11
main.py
11
main.py
@@ -16,6 +16,7 @@ class Auditui:
|
|||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.auth = None
|
self.auth = None
|
||||||
|
self.client = None
|
||||||
|
|
||||||
def login_to_audible(self):
|
def login_to_audible(self):
|
||||||
auth_file = self.AUTH_PATH
|
auth_file = self.AUTH_PATH
|
||||||
@@ -25,6 +26,7 @@ class Auditui:
|
|||||||
try:
|
try:
|
||||||
self.auth = audible.Authenticator.from_file(str(auth_file))
|
self.auth = audible.Authenticator.from_file(str(auth_file))
|
||||||
print("Loaded existing authentication.")
|
print("Loaded existing authentication.")
|
||||||
|
self.client = audible.Client(auth=self.auth)
|
||||||
return
|
return
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Failed to load existing auth: {e}")
|
print(f"Failed to load existing auth: {e}")
|
||||||
@@ -51,6 +53,7 @@ class Auditui:
|
|||||||
auth_file.parent.mkdir(parents=True, exist_ok=True)
|
auth_file.parent.mkdir(parents=True, exist_ok=True)
|
||||||
self.auth.to_file(str(auth_file))
|
self.auth.to_file(str(auth_file))
|
||||||
print("Authentication successful! Credentials saved.")
|
print("Authentication successful! Credentials saved.")
|
||||||
|
self.client = audible.Client(auth=self.auth)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Authentication failed: {e}")
|
print(f"Authentication failed: {e}")
|
||||||
import traceback
|
import traceback
|
||||||
@@ -159,8 +162,6 @@ class Auditui:
|
|||||||
print(f"Total: {len(items)} books")
|
print(f"Total: {len(items)} books")
|
||||||
|
|
||||||
def list_library(self):
|
def list_library(self):
|
||||||
client = audible.Client(auth=self.auth)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
print("\nFetching your library...")
|
print("\nFetching your library...")
|
||||||
|
|
||||||
@@ -169,7 +170,7 @@ class Auditui:
|
|||||||
page_size = 50
|
page_size = 50
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
library = client.get(
|
library = self.client.get(
|
||||||
path="library",
|
path="library",
|
||||||
num_results=page_size,
|
num_results=page_size,
|
||||||
page=page,
|
page=page,
|
||||||
@@ -201,8 +202,6 @@ class Auditui:
|
|||||||
print(f"Error fetching library: {e}")
|
print(f"Error fetching library: {e}")
|
||||||
|
|
||||||
def list_unfinished(self):
|
def list_unfinished(self):
|
||||||
client = audible.Client(auth=self.auth)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
print("\nFetching your library...")
|
print("\nFetching your library...")
|
||||||
|
|
||||||
@@ -211,7 +210,7 @@ class Auditui:
|
|||||||
page_size = 50
|
page_size = 50
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
library = client.get(
|
library = self.client.get(
|
||||||
path="library",
|
path="library",
|
||||||
num_results=page_size,
|
num_results=page_size,
|
||||||
page=page,
|
page=page,
|
||||||
|
|||||||
Reference in New Issue
Block a user