fixed some file handling bugs with dict_pics.txt

This commit is contained in:
spbeach46 2021-04-21 17:12:35 -07:00
parent 2f99c63165
commit 6ccce53b10

View File

@ -323,22 +323,22 @@ class CurateData:
print('url list not found. download aborted')
return
breakpoint()
temp_dict_pics = {k:target_dir+re.search(r'[^/]+(?=/\$_|.jpg)', k, re.IGNORECASE).group()+'.jpg' for k in temp_pics_source_list}
with open('dict_pics.txt', 'w') as f:
try:
breakpoint()
try:
with open('dict_pics.txt') as f:
dict_pics = json.load(f)
dict_pics.update(temp_dict_pics)
json.dump(dict_pics, f) # TODO This completely overwrites the old file. Fix to exclude corruptions
except ValueError:
temp_dict_pics.update(dict_pics)
with open('dict_pics.txt', 'w') as f:
json.dump(temp_dict_pics, f)
dict_pics = temp_dict_pics
except (ValueError, FileNotFoundError):
json.dump(temp_dict_pics, f)
dict_pics = temp_dict_pics
def dl_pic(pic,dict_pics):
breakpoint()
if os.path.exists(dict_pics[pic]): # or call temp_dict_pics[pic] can work
pass
@ -348,7 +348,7 @@ class CurateData:
with open(temp_dict_pics[pic], 'wb') as f: # Or call dict_pics[pic] can work
shutil.copyfileobj(r.raw, f)
bargs = [(dict_pics, temp_dict_pics) for pic in temp_dict_pics]
bargs = [(dict_pics, pic) for pic in temp_pics_source_list] # TODO not sure this is correct list of tuples needed
with concurrent.futures.ThreadPoolExecutor() as executor:
for future in executor.map(lambda p: dl_pic(*p), bargs):
future