flask-soc-site/upload/csv_parse.py
2024-08-29 21:03:36 +02:00

23 lines
597 B
Python

import csv
from io import StringIO
from validators import ipv4, ipv6, url, domain
def extract(uploaded):
hosts = []
content = uploaded.read()
decoded = content.decode("utf-8")
file = StringIO(decoded)
csv_data = csv.reader(file, delimiter=",")
for row in csv_data:
for value in row:
if url(value):
hosts.append(value)
elif domain(value):
hosts.append(value)
elif ipv4(value):
hosts.append(value)
elif ipv6(value):
hosts.append(value)
return hosts