#!/usr/bin/env python3

import pandas as pd
import matplotlib.pyplot as plt
import sys
import os

if len(sys.argv) != 2:
    print("Usage: python3 generate_web_graph.py <csv_file>")
    exit(1)

csv_file = sys.argv[1]
if not os.path.exists(csv_file):
    print(f"[!] CSV file {csv_file} not found.")
    exit(1)

df = pd.read_csv(csv_file)
status_counts = df['StatusCode'].value_counts().sort_index()

plt.figure(figsize=(8, 5))
status_counts.plot(kind='bar')
plt.xlabel('HTTP Status Code')
plt.ylabel('Number of Paths')
plt.title('Web Directory Scan - HTTP Status Codes')
plt.xticks(rotation=0)
plt.tight_layout()

png_file = csv_file.replace('.csv', '.png')
plt.savefig(png_file)
print(f"[+] Graph saved as {png_file}")
