-
Notifications
You must be signed in to change notification settings - Fork 0
/
unfucker.py
33 lines (29 loc) · 1.16 KB
/
unfucker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import sys
import re
def clean_text(input_text):
words_to_remove = ['fucking', 'fuck off', 'fuck']
for word in words_to_remove:
pattern = r'\b' + re.escape(word) + r'\b\s*'
input_text = re.sub(pattern, '', input_text)
return input_text
if __name__ == "__main__":
if len(sys.argv) < 2:
print("Usage: python text_cleaner.py --file <file_path> or --text '<input_text>'")
else:
if sys.argv[1] == '--file' and len(sys.argv) == 3:
file_path = sys.argv[2]
try:
with open(file_path, 'r') as file:
text = file.read()
cleaned_text = clean_text(text)
print("Cleaned Text:")
print(cleaned_text)
except FileNotFoundError:
print(f"Error: The file '{file_path}' does not exist.")
elif sys.argv[1] == '--text' and len(sys.argv) == 3:
text = sys.argv[2]
cleaned_text = clean_text(text)
print("Cleaned Text:")
print(cleaned_text)
else:
print("Invalid input. Usage: python text_cleaner.py --file <file_path> or --text '<input_text>'")