From 2296aea463505c3b9cccfb5a6eaca4570df5fa13 Mon Sep 17 00:00:00 2001 From: Cole Deck Date: Fri, 10 May 2024 12:58:17 -0500 Subject: [PATCH] Add useful print statements --- read_datasheet.py | 11 +++++++---- requirements.txt | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/read_datasheet.py b/read_datasheet.py index cd4c631..2c76bfb 100755 --- a/read_datasheet.py +++ b/read_datasheet.py @@ -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 diff --git a/requirements.txt b/requirements.txt index b32b361..1eaa55b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ # Runtime -camelot-py[base] +camelot-py[base]==0.9.0 opencv-python pypdf2==2.12.1 alive-progress