-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcsv-docx.py
70 lines (56 loc) · 1.99 KB
/
csv-docx.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import pandas as pd
from docx import Document
from docx.shared import Pt, RGBColor
from docx.enum.text import WD_ALIGN_PARAGRAPH
# Load the CSV file
csv_file = "findings.csv"
data = pd.read_csv(csv_file)
# Create a Word document
doc = Document()
# Add a title
title = doc.add_heading('Security Audit Findings Report', 0)
title.alignment = WD_ALIGN_PARAGRAPH.CENTER
# Define severity colors
severity_colors = {
'High': RGBColor(255, 0, 0), # Red
'Medium': RGBColor(255, 165, 0), # Orange
'Low': RGBColor(255, 255, 0) # Yellow
}
# Iterate through each row in the DataFrame
for _, row in data.iterrows():
if pd.isna(row['Findings']):
continue
# Add finding as heading
heading = doc.add_heading(f"Finding: {row['Findings']}", level=1)
# Add description
p = doc.add_paragraph()
p.add_run("Description: ").bold = True
p.add_run(str(row['Description']).replace('\n', ' ').replace('\r', ' '))
# Add affected IPs
p = doc.add_paragraph()
p.add_run("Affected IPs: ").bold = True
p.add_run(str(row['AffectedIP']))
# Add severity with color
p = doc.add_paragraph()
p.add_run("Severity: ").bold = True
severity_text = p.add_run(str(row['Severity']))
if str(row['Severity']) in severity_colors:
severity_text.font.color.rgb = severity_colors[str(row['Severity'])]
# Add remediation
p = doc.add_paragraph()
p.add_run("Remediation: ").bold = True
p.add_run(str(row['Remediation']))
# Add plugin output
p = doc.add_paragraph()
p.add_run("Plugin Output: ").bold = True
p.add_run(str(row['PluginOutput']))
# Add plugin reference
p = doc.add_paragraph()
p.add_run("Reference: ").bold = True
p.add_run(str(row['Plugin '].strip())) # strip the trailing space
# Add a page break for the next entry
doc.add_page_break()
# Save the Word document
output_file = "security_findings_report.docx"
doc.save(output_file)
print(f"Word document created: {output_file}")