-
Notifications
You must be signed in to change notification settings - Fork 64
/
Validator.py
31 lines (26 loc) · 1.26 KB
/
Validator.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
import csv
valid_categories = ['SSL', 'IP', 'DNS', 'URL', 'MD5', 'SHA1', 'SHA256', 'CVEID', 'RANSOMWARELEAK', 'JA3', 'NamePipe']
banner = "Validating CSV file... \nIf no error is shown the CSV is correct."
def validate_csv(csv_file):
with open(csv_file, 'r') as file:
reader = csv.DictReader(file, delimiter=';')
for idx, row in enumerate(reader, start=1): # Start at line 2 (assuming 1-indexed line numbers)
vendor = row.get('Vendor')
description = row.get('Description')
category = row.get('Category')
url = row.get('Url')
if not vendor:
print(f"Vendor field is empty in line {idx + 1}")
if not description:
print(f"Description field is empty in line {idx + 1}")
if not category:
print(f"Category field is empty in line {idx + 1}")
if not url:
print(f"Url field is empty in line {idx + 1}")
elif category not in valid_categories:
print(f"Invalid category '{category}' in line {idx + 1}")
print(banner)
# For linux use: csv_file = '../ThreatIntelFeeds.csv'
# For windows use: csv_file = '..\ThreatIntelFeeds.csv'
csv_file = '../ThreatIntelFeeds.csv'
validate_csv(csv_file)