Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update for selecting the file #1

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

*.txt
*.csv
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
109 changes: 85 additions & 24 deletions rip.py
Original file line number Diff line number Diff line change
@@ -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()