19
19
query_login_form
20
20
21
21
# Set Vars
22
- version = "0.6 " # Version number of script
22
+ version = "1.0 " # Version number of script
23
23
error_count = 0
24
24
script_dir = os .path .join (Path .home (), "AutoBooks" )
25
25
csv_path = os .path .join (script_dir , 'web_known_files.csv' )
51
51
file_log_format = "{time:HH:mm:ss A} [{name}:{function}] {level}: {extra[scrubbed]}\n {exception}"
52
52
redacting_formatter = RedactingFormatter (patterns = patterns , source_fmt = file_log_format )
53
53
logger .configure (handlers = [
54
- {'sink' : sys .stderr , "format" : console_log_format },
54
+ {'sink' : sys .stderr , "format" : console_log_format , 'level' : 'DEBUG' },
55
55
{'sink' : LOG_FILENAME ,
56
56
"format" : redacting_formatter .format , "retention" : 10 },
57
57
])
71
71
monitor = cronitor .Monitor (config ['cronitor_monitor' ])
72
72
73
73
74
- # Function to process the books.
74
+ # Function to process the odm files into books.
75
75
def process (odm_list ):
76
76
global error_count
77
77
good_odm_list = []
@@ -123,12 +123,14 @@ def cleanup(m4b_list, odm_list, odm_folder):
123
123
logger .info ("Moved file pair {} to source files" , x )
124
124
125
125
126
+ # Function to authenticate with Overdrive
126
127
def login (library ):
127
128
login_session = requests .Session ()
128
129
logger .info ("Logging into: {}" , library ["subdomain" ])
129
130
box = login_session .get (f'https://{ library ["subdomain" ]} .overdrive.com/account/ozone/sign-in?forward=%2F' )
130
131
# logger.success('Fetched login page. Status Code: {}', box.status_code)
131
132
form_list = parse_form (box , "loginForms" )['forms' ]
133
+ print (form_list )
132
134
login_form = query_login_form (form_list , library ['select_box' ])
133
135
sleep (0.5 )
134
136
auth = login_session .post (f'https://{ library ["subdomain" ]} .overdrive.com/account/signInOzone' ,
@@ -142,7 +144,10 @@ def login(library):
142
144
})
143
145
logger .success ("Logged into: {} Status Code: {} " , library ["subdomain" ], auth .status_code )
144
146
# 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
146
151
147
152
148
153
# Function to download loans from OverDrive page
@@ -209,12 +214,10 @@ def run():
209
214
# For every library, open site, attempt sign in, and attempt download.
210
215
for i in range (0 , library_count ):
211
216
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 ' ])
213
218
sleep (0.5 )
214
219
base_url , ils_name , session = login (lib_conf )
215
220
216
- if not base_url .endswith ('/' ):
217
- base_url = base_url + '/'
218
221
loans = session .get (f'{ base_url } account/loans' )
219
222
sleep (0.5 )
220
223
if loans .status_code == 200 :
@@ -233,7 +236,7 @@ def run():
233
236
else :
234
237
df_out .to_csv (csv_path , mode = 'w' , index = False , header = True )
235
238
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 ' ])
237
240
error_count += 1
238
241
session .close ()
239
242
logger .info ("AutoBooksWeb Complete" )
0 commit comments