49 lines
1.2 KiB
Python
49 lines
1.2 KiB
Python
# scripts/random_text_generator.py
|
|
|
|
import random
|
|
import string
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
|
|
def anonymize_text(text: str) -> str:
|
|
result = []
|
|
|
|
for character in text:
|
|
if character.islower():
|
|
result.append(random.choice(string.ascii_lowercase))
|
|
elif character.isupper():
|
|
result.append(random.choice(string.ascii_uppercase))
|
|
elif character.isdigit():
|
|
result.append(random.choice(string.digits))
|
|
else:
|
|
result.append(character)
|
|
|
|
return "".join(result)
|
|
|
|
|
|
def main() -> None:
|
|
if len(sys.argv) != 2:
|
|
print("Usage: python scripts/random_text_generator.py <input_file>")
|
|
sys.exit(1)
|
|
|
|
input_path = Path(sys.argv[1])
|
|
|
|
if not input_path.is_file():
|
|
print(f"File not found: {input_path}")
|
|
sys.exit(1)
|
|
|
|
source_text = input_path.read_text(encoding="utf-8")
|
|
anonymized_text = anonymize_text(source_text)
|
|
|
|
output_path = input_path.with_name(
|
|
f"{input_path.stem}_anonymized{input_path.suffix}"
|
|
)
|
|
|
|
output_path.write_text(anonymized_text, encoding="utf-8")
|
|
|
|
print(f"Anonymized file saved to: {output_path}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main() |