Skip to content

Commit 0d43f56

Browse files
author
Ivy Bowman
committed
Preparing for version 1.0
Code cleanup, fixing instructions and example config,
1 parent af17ed7 commit 0d43f56

File tree

5 files changed

+23
-22
lines changed

5 files changed

+23
-22
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ for personal use with your preferred audiobook player during the loan period.
2929

3030
# Usage
3131

32-
- AutoBooks DL/Fulfill: `autobooks`
33-
- AutoBooks Web: `autobooks-web`
32+
- AutoBooks: `autobooks`
3433
- AutoBooks Discord bot: `autobooks-discord`
3534

3635
# Credits & Tools Used

autobooks/AutoBooks.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
query_login_form
2020

2121
# Set Vars
22-
version = "0.6" # Version number of script
22+
version = "1.0" # Version number of script
2323
error_count = 0
2424
script_dir = os.path.join(Path.home(), "AutoBooks")
2525
csv_path = os.path.join(script_dir, 'web_known_files.csv')
@@ -51,7 +51,7 @@
5151
file_log_format = "{time:HH:mm:ss A} [{name}:{function}] {level}: {extra[scrubbed]}\n{exception}"
5252
redacting_formatter = RedactingFormatter(patterns=patterns, source_fmt=file_log_format)
5353
logger.configure(handlers=[
54-
{'sink': sys.stderr, "format": console_log_format},
54+
{'sink': sys.stderr, "format": console_log_format, 'level': 'DEBUG'},
5555
{'sink': LOG_FILENAME,
5656
"format": redacting_formatter.format, "retention": 10},
5757
])
@@ -71,7 +71,7 @@
7171
monitor = cronitor.Monitor(config['cronitor_monitor'])
7272

7373

74-
# Function to process the books.
74+
# Function to process the odm files into books.
7575
def process(odm_list):
7676
global error_count
7777
good_odm_list = []
@@ -123,12 +123,14 @@ def cleanup(m4b_list, odm_list, odm_folder):
123123
logger.info("Moved file pair {} to source files", x)
124124

125125

126+
# Function to authenticate with Overdrive
126127
def login(library):
127128
login_session = requests.Session()
128129
logger.info("Logging into: {}", library["subdomain"])
129130
box = login_session.get(f'https://{library["subdomain"]}.overdrive.com/account/ozone/sign-in?forward=%2F')
130131
# logger.success('Fetched login page. Status Code: {}', box.status_code)
131132
form_list = parse_form(box, "loginForms")['forms']
133+
print(form_list)
132134
login_form = query_login_form(form_list, library['select_box'])
133135
sleep(0.5)
134136
auth = login_session.post(f'https://{library["subdomain"]}.overdrive.com/account/signInOzone',
@@ -142,7 +144,10 @@ def login(library):
142144
})
143145
logger.success("Logged into: {} Status Code: {} ", library["subdomain"], auth.status_code)
144146
# print("AUTH URL: ", auth.url)
145-
return auth.url, login_form['ilsName'], login_session
147+
base_url = auth.url
148+
if not base_url.endswith('/'):
149+
base_url = base_url + '/'
150+
return base_url, login_form['ilsName'], login_session
146151

147152

148153
# Function to download loans from OverDrive page
@@ -209,12 +214,10 @@ def run():
209214
# For every library, open site, attempt sign in, and attempt download.
210215
for i in range(0, library_count):
211216
lib_conf = parser['library_' + str(i)]
212-
logger.info("Begin Processing library: {}", lib_conf['library_name'])
217+
logger.info("Begin Processing library: {}", lib_conf['name'])
213218
sleep(0.5)
214219
base_url, ils_name, session = login(lib_conf)
215220

216-
if not base_url.endswith('/'):
217-
base_url = base_url + '/'
218221
loans = session.get(f'{base_url}account/loans')
219222
sleep(0.5)
220223
if loans.status_code == 200:
@@ -233,7 +236,7 @@ def run():
233236
else:
234237
df_out.to_csv(csv_path, mode='w', index=False, header=True)
235238
else:
236-
logger.warning("Can't find books skipped library: {}", lib_conf['library_name'])
239+
logger.warning("Can't find books skipped library: {}", lib_conf['name'])
237240
error_count += 1
238241
session.close()
239242
logger.info("AutoBooksWeb Complete")

autobooks/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,4 @@ def query_login_form(form_list, select):
8282
for form, index in form_list:
8383
if select in form['displayName']:
8484
x = form_list.index(form)
85-
return form_list[x]
85+
return form_list[x]

autobooks_template.ini

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,17 @@ discord_bot_token =
88
test_args = False
99
test_run = False
1010

11-
# Folders .odm Location, and m4b output folder
12-
odm_folder =
11+
# Folder to output the generated m4b files to.
1312
out_folder =
1413

15-
#To add more libraries just make a copy of the below section and increment the number.
14+
# To add more libraries just make a copy of the below section and increment the number.
1615
[library_0]
17-
library_name =
18-
#Name of library, used in log messages
19-
library_subdomain =
20-
#Overdrive subdomain Ex: "examplepage" from "https://examplepage.overdrive.com/"
21-
library_select = False
22-
#Library select box contents here. If not used for sign in put "False" Ex: "Example County Library"
16+
name =
17+
# Display name of library, used in log messages.
18+
subdomain =
19+
# Overdrive subdomain Ex: "examplepage" from "https://examplepage.overdrive.com/"
20+
select_box = False
21+
# Library select box contents here. If not used for sign in put "False" Ex: "Example County Library"
2322
card_number =
2423
card_pin =
25-
#Library card pin here. If not used for sign in put "False"
24+
# Library card pin here. If not used for sign in put "False"

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from setuptools import setup
22

3-
VERSION = '0.6'
3+
VERSION = '1.0'
44
DESCRIPTION = 'Python tool to automate processing a batch of OverDrive audiobooks.'
55
LONG_DESCRIPTION = 'Python tool to automate processing a batch of OverDrive audiobooks.'
66

0 commit comments

Comments
 (0)