import argparse import csv import gzip import sys def domains(path): with gzip.open(path, "rt", encoding="utf-8") as source: for line in source: domain = line.strip().lower().rstrip(".") if domain: yield domain parser = argparse.ArgumentParser(description="Find keyword matches for security review") parser.add_argument("file") parser.add_argument("--terms", nargs="+", required=True) args = parser.parse_args() writer = csv.writer(sys.stdout) writer.writerow(["domain", "matched_terms"]) for domain in domains(args.file): matches = [term for term in args.terms if term.lower() in domain] if matches: writer.writerow([domain, ";".join(matches)])