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

View File

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