-
Notifications
You must be signed in to change notification settings - Fork 0
/
detection.py
28 lines (22 loc) · 935 Bytes
/
detection.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
def read_sensitive_keywords(filename):
try:
with open(filename, "r") as keywords_file:
keywords = [line.strip() for line in keywords_file.readlines()]
return keywords
except FileNotFoundError:
print(f"Error: {filename} not found.")
return []
def check_sensitive_data(result_text, sensitive_keywords):
detected_keywords = []
for keyword in sensitive_keywords:
if keyword.lower() in result_text.lower():
detected_keywords.append(keyword)
return detected_keywords
def write_detected_keywords(detected_keywords, output_filename):
try:
with open(output_filename, "w") as output_file:
for keyword in detected_keywords:
output_file.write(f"{keyword}\n")
print(f"Detected sensitive keywords written to {output_filename}")
except IOError as e:
print(f"Error writing to {output_filename}: {e}")