-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathreport.py
More file actions
80 lines (65 loc) · 3.02 KB
/
report.py
File metadata and controls
80 lines (65 loc) · 3.02 KB
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
71
72
73
74
75
76
77
78
79
80
import yaml
from colorama import Fore, Style
from mail import reports
def generate_report(template_titles):
table_data = []
for report in reports:
status_icons = {
"Inbox": "✔" if report['status'] == 'Inbox' else "",
"Spam": "✔" if report['status'] == 'Spam' else "",
"Blocked": "✔" if report['status'] == 'Blocked' else ""
}
title = template_titles.get(report['template'], 'No Title')
table_data.append([
title,
report['subject'],
status_icons['Inbox'],
status_icons['Spam'],
status_icons['Blocked'],
report.get('attachment_path', "N/A")
])
headers = ['Mail Template', 'Mail Subject', 'Inbox', 'Spam', 'Not Bypassed', 'Attachment Path']
max_lengths = [max(len(str(row[i])) for row in [headers] + table_data) for i in range(len(headers))]
header_row = " | ".join(f"{headers[i]:<{max_lengths[i]}}" for i in range(len(headers)))
print(header_row)
print("-" * len(header_row))
for row in table_data:
print(" | ".join(f"{str(row[i]):<{max_lengths[i]}}" for i in range(len(row))))
print(Fore.LIGHTYELLOW_EX + "\nAll reports completed. Exiting the script." + Style.RESET_ALL)
exit()
def load_template_titles():
template_titles = {}
for report in reports:
template_file = f"./templates/{report['template']}"
try:
with open(template_file, 'r') as f:
template_data = yaml.safe_load(f)
template_titles[report['template']] = template_data.get('Title', 'No Title')
except FileNotFoundError:
print(Fore.RED + f"Template file '{template_file}' not found." + Style.RESET_ALL)
template_titles[report['template']] = 'No Title'
except yaml.YAMLError:
print(Fore.RED + f"Error reading YAML from '{template_file}'." + Style.RESET_ALL)
template_titles[report['template']] = 'No Title'
return template_titles
def report_menu():
if not reports:
print("No reports available to display.")
return
template_titles = load_template_titles()
for report in reports:
title = template_titles.get(report['template'], 'No Title')
print(f"\n{Fore.LIGHTCYAN_EX}Template Title:{Style.RESET_ALL} {title}")
print(f"{Fore.LIGHTCYAN_EX}Mail Subject:{Style.RESET_ALL} {report['subject']}")
print(f"{Fore.LIGHTCYAN_EX}Reference ID:{Style.RESET_ALL} {report['reference_id']}")
print("Select status: ")
print("1. Inbox")
print("2. Spam")
print("3. Not (not seen)")
status_choice = input( Fore.LIGHTCYAN_EX + "Enter the number corresponding to the status: " + Style.RESET_ALL).strip()
status_map = {'1': 'Inbox', '2': 'Spam', '3': 'Blocked'}
if status_choice in status_map:
report['status'] = status_map[status_choice]
else:
print(Fore.RED + "Invalid choice. Status not updated." + Style.RESET_ALL)
generate_report(template_titles)