@@ -152,7 +152,7 @@ def cleanup(m4bs, odms, odmfolder):
152
152
# Function for login
153
153
def web_login (driver , name , cardno , pin , select ):
154
154
global error_count
155
- web_logger .info ("web_login: Logging into %s" , name )
155
+ web_logger .info ("web_login: Logging into library: %s" , name )
156
156
# Attempt selecting library from dropdown
157
157
if select != "false" :
158
158
select_box = driver .find_element (By .XPATH , '//input[@id="signin-options"]' )
@@ -178,11 +178,11 @@ def web_dl(driver, df, name):
178
178
#Gather all book title elements and check if any found
179
179
books = driver .find_elements (By .XPATH , '//a[@tabindex="0"][@role="link"]' )
180
180
if len (books ) == 0 :
181
- web_logger .warning ("Can't find books skipped library %s" , name )
181
+ web_logger .warning ("Can't find books skipped library: %s" , name )
182
182
error_count += 1
183
183
return ()
184
184
else :
185
- web_logger .info ("web_dl: Begin DL from %s " , name )
185
+ web_logger .info ("web_dl: Begin DL from library: %s " , name )
186
186
bookcount = 0
187
187
for i in books :
188
188
#Fetch info about the book
@@ -196,14 +196,13 @@ def web_dl(driver, df, name):
196
196
if str (book_id ) in df ['book_id' ].to_string ():
197
197
web_logger .info ('web_dl: Skipped %s found in known books' , book_title )
198
198
else :
199
-
200
199
# Download book
201
200
driver .get (book_dl_url )
202
201
web_logger .info ("web_dl: Downloaded book: %s" , book_title )
203
202
book_odm = max (glob .glob ("*.odm" ), key = os .path .getmtime )
203
+ bookcount += 1
204
204
205
205
#Add book data to vars
206
- bookcount += 1
207
206
library_list .append (name )
208
207
book_id_list .append (book_id )
209
208
book_title_list .append (book_title )
@@ -279,10 +278,12 @@ def web_run():
279
278
driver = webdriver .Chrome (options = options )
280
279
281
280
# Attempt to read known files csv for checking books
282
- try :
281
+ if os . path . exists ( csv_path ) :
283
282
df = pd .read_csv (csv_path , sep = "," )
284
- except FileNotFoundError :
285
- df = False
283
+ else :
284
+ df = pd .DataFrame ({
285
+ 'book_id' : book_id_list ,
286
+ })
286
287
os .chdir (os .path .join (scriptdir ,"web_downloads" ))
287
288
# For every library, open site, attempt sign in, and attempt download.
288
289
for i in range (0 , len (parser .sections ())):
@@ -305,7 +306,7 @@ def web_run():
305
306
'book_id' : book_id_list ,
306
307
'book_title' : book_title_list ,
307
308
'book_odm' : book_odm_list
308
- })
309
+ })
309
310
if os .path .exists (csv_path ):
310
311
df_out .to_csv (csv_path , mode = 'a' , index = False , header = False )
311
312
else :
0 commit comments