From 6cfa798902a398570c8f8769c19d32158ed56bbb Mon Sep 17 00:00:00 2001 From: spbeach46 Date: Tue, 27 Apr 2021 22:42:55 -0700 Subject: [PATCH] Fixing more bugs in dl_pictures --- ebay_api.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/ebay_api.py b/ebay_api.py index 182563c..59a47de 100644 --- a/ebay_api.py +++ b/ebay_api.py @@ -278,12 +278,16 @@ class CurateData: temp_pics_source_list = list(set(expanded_class.PictureURL.to_list())) # prolly need to create set long before df... immediately after Shopping or trading call # defined in the download function - with open('temp_pics_source_list.txt', 'a+') as f: # Temp iterable for use w/executor - try: + + try: + with open('temp_pics_source_list.txt') as f: temp_pics_source_list = json.load(f) temp_pics_source_list.append(temp_pics_source_list) - json.dump(temp_pics_source_list, f) # TODO This creates duplicates incorrectly - except ValueError: + temp_pics_source_list = list(set(temp_pics_source_list)) + with open('temp_pics_source_list.txt', 'w') as f: + json.dump(temp_pics_source_list, f) + except (ValueError, FileNotFoundError): + with open('temp_pics_source_list.txt', 'w') as f: json.dump(temp_pics_source_list, f) return expanded_class, expanded_dropd @@ -298,17 +302,17 @@ class CurateData: with open('target_dirs.txt', 'r+') as f: # TODO you can add option to change directory here, too. Look up how to have optional arguments target_dir = json.load(f) - except (ValueError, FileNotFoundError): # TODO doesn't seem to create target_dir from cwd. I think it's because ValueError should be FileNotFoundError? + except (ValueError, FileNotFoundError): target_dir = input('No target dirctory found. Create One? [y] or [n]:') if target_dir == ('y' or 'Y'): target_dir = input('Please provide full URL to destination folder:') with open('target_dirs.txt','w+') as f: json.dump(target_dir, f) else: - target_dir = os.getcwd() + target_dir = os.mkdir(os.getcwd()+os.sep+'training_images') with open('target_dirs.txt','w+') as f: json.dump(target_dir, f) - print('Creating default folder in current directory, ' + target_dir) # TODO does not concat correctly. Fix this + print('Creating default folder in current directory @ ' + target_dir) with open('temp_pics_source_list.txt') as f: try: @@ -316,7 +320,7 @@ class CurateData: temp_pics_source_list = args[0] else: temp_pics_source_list = json.load(f) - except ValueError: + except (ValueError, FileNotFoundError): if args: temp_pics_sources_list = args[0] else: