Add useful print statements

This commit is contained in:
Cole Deck 2024-05-10 12:58:17 -05:00
parent 341d2232d7
commit 2296aea463
2 changed files with 8 additions and 5 deletions

View File

@ -68,8 +68,9 @@ def find_file_noext(directory, prefix="part-hires"):
#print(directory, matching_files)
return matching_files
def rotate_and_crop_image(path, image_name, force_rotate=False):
def rotate_and_crop_image(path, image_name, force_rotate=False, partnum=""):
# Open the image file
fprint("Generating thumbnail image for part " + partnum)
image_path = path + "/" + image_name
with Image.open(image_path) as img:
# Check if the image is wider than it is tall
@ -88,6 +89,7 @@ def rotate_and_crop_image(path, image_name, force_rotate=False):
# Save or display the image
img_cropped.save(path + "/" + "thumbnail-" + image_name) # Save the cropped image
def parse(filename, output_dir, partnum, dstype, weburl, extra):
tables = []
@ -187,10 +189,10 @@ def parse(filename, output_dir, partnum, dstype, weburl, extra):
count += 1
if os.path.exists(output_dir + "/found_part_hires"):
rotate_and_crop_image(output_dir, find_file_noext(output_dir, prefix="part-hires")[0], force_rotate=(dstype == "Alphawire"))
rotate_and_crop_image(output_dir, find_file_noext(output_dir, prefix="part-hires")[0], force_rotate=(dstype == "Alphawire"), partnum=partnum)
img = weburl + find_file_noext(output_dir, prefix="thumbnail-part-hires")[0]
elif len(find_file_noext(output_dir, prefix="part")) > 0:
rotate_and_crop_image(output_dir, find_file_noext(output_dir, prefix="part")[0], force_rotate=(dstype == "Alphawire"))
rotate_and_crop_image(output_dir, find_file_noext(output_dir, prefix="part")[0], force_rotate=(dstype == "Alphawire"), partnum=partnum)
img = weburl + find_file_noext(output_dir, prefix="thumbnail-part")[0]
else:
img = None
@ -408,7 +410,8 @@ def parse(filename, output_dir, partnum, dstype, weburl, extra):
json.dump(output_table["searchspecs"], json_file)
with open(output_dir + "/specs.json", 'w') as json_file:
json.dump(output_table["fullspecs"], json_file)
fprint("Datasheet values parsed and saved for " + partnum)
#print(json.dumps(output_table, indent=2))
touch(output_dir + "/parsed") # mark as parsed
return True

View File

@ -1,5 +1,5 @@
# Runtime
camelot-py[base]
camelot-py[base]==0.9.0
opencv-python
pypdf2==2.12.1
alive-progress