The script didn't push, pushing.

This commit is contained in:
Lord_Devi 2024-07-19 00:33:35 -04:00
parent 0d3cd1c855
commit 81f8cda247

View file

@ -0,0 +1,53 @@
#!/usr/bin/env python3
import os
import sys
import csv
import argparse
def find_project_root():
"""Find the project root by locating the 'bin' directory."""
current_path = os.path.abspath(__file__)
while current_path != os.path.dirname(current_path):
if os.path.basename(current_path) == 'bin':
return os.path.dirname(current_path)
current_path = os.path.dirname(current_path)
raise FileNotFoundError("Could not find project root. Make sure the script is in the 'bin' directory.")
def validate_csv_header(file_path):
"""Validate that the CSV file has the required header."""
with open(file_path, 'r') as csvfile:
reader = csv.reader(csvfile)
header = next(reader, None)
if header != ["domain", "alive", "website"]:
raise ValueError("CSV file does not have the correct header. Expected: domain,alive,website")
def extract_alive_domains(input_file, output_file):
"""Extract 'website' column for rows where 'alive' is 'yes' and write to output file."""
with open(input_file, 'r') as infile, open(output_file, 'w', newline='') as outfile:
reader = csv.DictReader(infile)
writer = csv.writer(outfile)
for row in reader:
if row['alive'].lower() == 'yes':
writer.writerow([row['website']])
def main():
parser = argparse.ArgumentParser(description="Extract alive domains from CSV file.")
parser.add_argument('input_file', help='Path to the input CSV file')
args = parser.parse_args()
try:
project_root = find_project_root()
output_file = os.path.join(project_root, 'alive-domains.csv')
validate_csv_header(args.input_file)
extract_alive_domains(args.input_file, output_file)
print(f"Successfully extracted alive domains to {output_file}")
except Exception as e:
print(f"Error: {str(e)}", file=sys.stderr)
sys.exit(1)
if __name__ == "__main__":
main()