Skip to content
This repository was archived by the owner on Apr 26, 2026. It is now read-only.

Commit b03a850

Browse files
committed
updated inspector tool to automatically create inspection files
1 parent 7a09be6 commit b03a850

1 file changed

Lines changed: 101 additions & 7 deletions

File tree

Lines changed: 101 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import json
2+
import datetime
3+
import os
4+
import re
25

36

4-
def process_json(json_file, output_file):
7+
def process_json(json_file, output_file, date_str):
58
with open(json_file, "r", encoding="utf-8") as f:
69
data = json.load(f)
710

@@ -16,23 +19,114 @@ def process_json(json_file, output_file):
1619
"ATTACK_SURFACE": set(),
1720
"SUSPECTED_REGION_OF_ORIGIN": set(),
1821
"FINAL_URL_STATUS": set(),
19-
"SURFACE_URL_STATUS": set()
22+
"SURFACE_URL_STATUS": set(),
2023
}
2124

2225
for case in data.values():
2326
for field in unique_values:
24-
unique_values[field].add(case[field])
27+
if field in case:
28+
unique_values[field].add(case[field])
2529

2630
case_count = len(data)
2731

2832
with open(output_file, "w", encoding="utf-8") as f:
29-
f.write(f"Total Cases: {case_count}\n\n")
33+
f.write(f'<div align="center">\n\n')
34+
f.write(f"# Database Inspection - {date_str}\n\n")
35+
f.write(f"## Total Cases: {case_count}\n\n")
36+
f.write(f"</div>\n\n")
37+
3038
for field, values in unique_values.items():
31-
f.write(f"{field}:\n")
32-
for value in values:
39+
f.write(f"## {field.replace('_', ' ').title()}\n")
40+
for value in sorted(values):
3341
f.write(f"- {value}\n")
3442
f.write("\n")
3543

44+
return case_count
45+
46+
47+
def count_entries_from_file(path):
48+
with open(path, "r", encoding="utf-8") as f:
49+
data = json.load(f)
50+
if isinstance(data, dict):
51+
return len(data)
52+
elif isinstance(data, list):
53+
return len(data)
54+
return 0
55+
56+
57+
def append_other_counts(output_file, counts_dict):
58+
with open(output_file, "a", encoding="utf-8") as f:
59+
f.write("## Additional Entries\n")
60+
for name, count in counts_dict.items():
61+
f.write(f"- **{name}**: {count} entries\n")
62+
63+
64+
def update_readme(
65+
readme_path, date_str, inspection_filename, case_count, additional_counts
66+
):
67+
with open(readme_path, "r", encoding="utf-8") as f:
68+
content = f.read()
69+
70+
additional_lines = "\n".join(
71+
f"- **{name}**: {count} entries" for name, count in additional_counts.items()
72+
)
73+
74+
new_section = f"""<!-- INSPECTION-START -->
75+
## Latest Database Inspection - {date_str}
76+
77+
**Inspection File**: [`{inspection_filename}`](Inspection-Database/{inspection_filename})
78+
**Total Cases**: {case_count}
79+
80+
{additional_lines}
81+
<!-- INSPECTION-END -->"""
82+
83+
pattern = r"<!-- INSPECTION-START -->(.*?)<!-- INSPECTION-END -->"
84+
if re.search(pattern, content, flags=re.DOTALL):
85+
content = re.sub(pattern, new_section, content, flags=re.DOTALL)
86+
else:
87+
# Insert before final closing </div> to keep formatting
88+
insert_point = content.rfind("</div>")
89+
if insert_point == -1:
90+
content += "\n\n" + new_section
91+
else:
92+
content = (
93+
content[:insert_point] + new_section + "\n\n" + content[insert_point:]
94+
)
95+
96+
with open(readme_path, "w", encoding="utf-8") as f:
97+
f.write(content)
98+
3699

37100
if __name__ == "__main__":
38-
process_json("../Database-Files/Edit-Database/Compromised-Discord-Accounts.json", "../inspection.txt")
101+
today = datetime.datetime.now().strftime("%Y-%m-%d")
102+
inspection_dir = "../Database-Files/Inspection-Database"
103+
os.makedirs(inspection_dir, exist_ok=True)
104+
inspection_filename = "Inspection.md"
105+
inspection_path = os.path.join(inspection_dir, inspection_filename)
106+
107+
json_file = "../Database-Files/Edit-Database/Compromised-Discord-Accounts.json"
108+
readme_path = "../Database-Files/README.md"
109+
110+
# Count primary file
111+
case_count = process_json(json_file, inspection_path, today)
112+
113+
# Count entries from additional files
114+
additional_counts = {
115+
"Discord IDs": count_entries_from_file(
116+
"../Database-Files/Filter-Database/Discord-IDs.json"
117+
),
118+
"Malicious URLs": count_entries_from_file(
119+
"../Database-Files/Filter-Database/Malicious-URLs.json"
120+
),
121+
"Discord Servers": count_entries_from_file(
122+
"../Database-Files/Filter-Database/Discord-Servers.json"
123+
),
124+
"Global URLs": count_entries_from_file(
125+
"../Database-Files/Filter-Database/Global-URLs.json"
126+
),
127+
}
128+
129+
append_other_counts(inspection_path, additional_counts)
130+
update_readme(
131+
readme_path, today, inspection_filename, case_count, additional_counts
132+
)

0 commit comments

Comments
 (0)