I have this python code: [code] Firstly, I was only able to determine typing imports, I…
- User
I have this python code:
from typing import Set, Tuple img_extensions = ['jpg', 'jpeg', 'png', 'gif', 'webp'] class DirectoryScanner: @staticmethod def get_paths_and_sizes_scandir(dir_path: str) -> Set[Tuple[str, int]]: image_data = set() subdirs = [] with os.scandir(dir_path) as entries: for entry in entries: if entry.is_file() and any(entry.name.endswith(ext) for ext in img_extensions) and entry.name != 'folder.jpg': image_data.add((entry.path, entry.stat().st_size)) elif entry.is_dir(): subdirs.append(entry.path) return image_data, subdirs @staticmethod def get_paths_and_sizes(start_dir: str): all_image_data = set() with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor: futures = {executor.submit(DirectoryScanner.get_paths_and_sizes_scandir, start_dir)} while futures: done, futures = concurrent.futures.wait( futures, return_when=concurrent.futures.FIRST_COMPLETED ) for future in done: image_data, subdirs = future.result() all_image_data.update(image_data) for subdir in subdirs: futures.add(executor.submit(DirectoryScanner.get_paths_and_sizes_scandir, subdir)) return all_image_dataFirstly, I was only able to determine typing imports, I do not know where concurrent comes from, so I need you to tell me that import and the pip install if I need to install something additional for this code. Secondly, I need to be able to use this code to compliment my SQLAlchemy database inserts into an SQLite database, I want to do it in the best most modern industry standard way possible. I would also like a breakdown of the code and a detailed explanation.
- Assistant
- User
I am doing this to select from a table in the database, fingerprint is a hash(string) and size is an int, together they form a unique pair, so I want to select it first to see if the one I want to add has already been added or not:
new_fingerprint = db.execute( select(Fingerprint).where([Fingerprint.fingerprint == new_fingerprint_hash and Fingerprint.size == size]) )Is this a valid way to do this?
- Assistant