diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fd40b6f --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ + +*.txt +*.csv diff --git a/LICENSE b/LICENSE index f8a63bb..a5695d5 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2024 Rick Kauffman +Copyright (c) 2024 Rick Kauffman, Ken Adams Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index b35b949..486f271 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ # email_ripper -A simple python script that reads a CSV file and finds email addresses for employees and partners. - +A python program that reads a CSV file, finds and categorizes email addresses, and then saves them to a text file and prints to the terminal along with the count for employees and partners. +Note: Specifically made to work with Microsoft Teams Webinar Attendance Reports # To use this application: -Download the csv file and save it in the application directory as data.csv +Run the program from its directory. From there, you will be able to select the CSV to parse. Output will be saved as a text file that you will name as well as printed in the terminal. # To run the program: python3 rip.py -A list of email addresses will be created one for employees, the other for partners. +A list of email addresses will be created; one for employees, the other for partners with an attendance summary at the top. diff --git a/rip.py b/rip.py index 7dfb9b5..51a71e2 100644 --- a/rip.py +++ b/rip.py @@ -1,24 +1,85 @@ -counter = 0 -employee = [] -partner = [] -cr = '\n' -with open('data.csv') as file: - for line in file: - mylist = line.split(',') - if 'Attendee' in mylist: - for item in mylist: - if '@' in item: - name,company = item.split('@') - if company == 'hpe.com': - if item.lower() not in employee: - employee.append(item.lower()) - if company != 'hpe.com': - if item.lower() not in partner: - partner.append(item.lower()) - for i in employee: - print(i) - print(f"{len(employee)} employees attended the call") - print('-----------------------------------------------') - for i in partner: - print(i) - print(f"{len(partner)} partners attended the call") +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()