Created
March 30, 2024 17:16
-
-
Save ajmeese7/95316038dea9342fb23f174edb01eb77 to your computer and use it in GitHub Desktop.
Parse out domains from exported Validin JSON data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import json | |
import sys | |
import os | |
def extract_domains(json_file_path): | |
try: | |
# Open and load the JSON file | |
with open(json_file_path, "r") as file: | |
data = json.load(file) | |
# Extract domain names | |
domains = [entry["value"] for entry in data] | |
# Create 'output' directory if it doesn't exist | |
output_dir = "output" | |
os.makedirs(output_dir, exist_ok=True) | |
# Write the domains to a new text file | |
base_name = os.path.splitext(os.path.basename(json_file_path))[0] | |
output_file_path = os.path.join(output_dir, f"{base_name}_domains.txt") | |
with open(output_file_path, "w") as output_file: | |
for domain in domains: | |
output_file.write(f"{domain}\n") | |
print(f"Domains have been extracted and saved to {output_file_path}") | |
except Exception as e: | |
print(f"An error occurred: {e}") | |
if __name__ == "__main__": | |
if len(sys.argv) != 2: | |
print("Usage: python3 validin-domain-parser.py <path_to_json_file>") | |
else: | |
json_file_path = sys.argv[1] | |
extract_domains(json_file_path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment