forked from xod442/email_ripper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrip.py
More file actions
85 lines (73 loc) · 2.96 KB
/
rip.py
File metadata and controls
85 lines (73 loc) · 2.96 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
81
82
83
84
85
import os
import tkinter as tk
from tkinter import filedialog, simpledialog
import chardet
def detect_encoding(filename):
"""Function to detect the encoding of the file"""
with open(filename, 'rb') as f:
raw_data = f.read()
result = chardet.detect(raw_data)
return result['encoding']
def process_attendees(filename, output_filename):
"""Function to define the employee and partners lists"""
employees = []
partners = []
if not os.path.exists(filename):
print(f"File {filename} does not exist.")
return
encoding = detect_encoding(filename)
with open(filename, encoding=encoding) as file:
for line in file:
my_list = line.split('\t')
if 'Attendee' in my_list:
for item in my_list:
if '@' in item:
name, domain = item.split('@')
if domain.strip() == 'hpe.com' and item.lower() not in employees:
employees.append(item.lower())
elif domain.strip() != 'hpe.com' and item.lower() not in partners:
partners.append(item.lower())
output_lines = []
output_lines.append('+++++++++++++++++++++++++++++++++++++++++++++++')
output_lines.append(f"{len(employees)} employees attended the call")
output_lines.append(f"{len(partners)} partners attended the call")
output_lines.append('+++++++++++++++++++++++++++++++++++++++++++++++')
output_lines.append("Employees:")
output_lines.append('-----------------------------------------------')
for i in employees:
output_lines.append(i)
output_lines.append('+++++++++++++++++++++++++++++++++++++++++++++++')
output_lines.append("Partners:")
output_lines.append('-----------------------------------------------')
for i in partners:
output_lines.append(i)
output_lines.append('+++++++++++++++++++++++++++++++++++++++++++++++')
# Print to terminal
for line in output_lines:
print(line)
# Write to output file
with open(output_filename, 'w', encoding='utf-8') as f:
for line in output_lines:
f.write(line + '\n')
print(f"Output written to {output_filename}")
def select_file():
"""Function to call tk to select files"""
root = tk.Tk()
root.withdraw() # Hide the root window
filename = filedialog.askopenfilename(
title="Select file",
filetypes=(("CSV files", "*.csv"), ("all files", "*.*"))
)
if filename:
output_filename = simpledialog.askstring("Output File",
"Enter the output file name (with .txt extension):")
if output_filename:
if not output_filename.endswith('.txt'):
output_filename += '.txt'
process_attendees(filename, output_filename)
else:
print("No output file name provided.")
else:
print("No file selected.")
if __name__ == "__main__":
select_file()