Skip to content

Commit

Permalink
[py-tx] Refomating
Browse files Browse the repository at this point in the history
  • Loading branch information
Mackay-Fisher committed Nov 26, 2024
1 parent 860f924 commit 1622ab1
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions python-threatexchange/threatexchange/cli/hash_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,35 +173,29 @@ def pre_processed_files() -> (
for rotation_type, processed_bytes in rotations.items():
yield file, processed_bytes, rotation_type, image_format

# Process each preprocessed file
for (
file,
processed_bytes,
rotation_type,
image_format,
) in pre_processed_files():
output_extension = f".{image_format.lower()}" if image_format else ".png"
# Use a temporary file with the correct extension
with tempfile.NamedTemporaryFile(
delete=not self.save_preprocess, suffix=output_extension
) as temp_file:
temp_file.write(processed_bytes)
temp_file.flush() # Ensure all data is written
temp_file_path = Path(temp_file.name)
for hasher in hashers:
hash_str = hasher.hash_from_file(temp_file_path)
if hash_str:
prefix = rotation_type.name if rotation_type else ""
print(f"{prefix} {hasher.get_name()} {hash_str}")
# Save output by renaming the temp file if needed
if self.save_preprocess:
suffix = (
f"_{rotation_type.name}" if rotation_type else "_unletterboxed"
)
output_path = file.with_stem(f"{file.stem}{suffix}").with_suffix(
output_extension
)
temp_file_path.rename(
output_path
) # Move temp file to desired location
temp_file_path.rename(output_path)
print(f"Processed image saved to: {output_path}")

0 comments on commit 1622ab1

Please sign in to comment.