Admin
Администратор
Разделение почты на Python по доменам
Простой python-скрипт для разделения логов и комбо по домену. Нет необходимости скачивать сомнительный инструмент в интернете.
Python:
from tkinter import Tk
from tkinter.filedialog import askopenfilename, asksaveasfilename
import os
def filter_emails_by_domains(emails, domains):
filtered_emails = set()
for email in emails:
for domain in domains:
if domain.lower() in email.lower():
filtered_emails.add(email)
break
return filtered_emails
def export_emails_to_txt(emails, filename):
with open(filename, 'w', encoding='utf-8') as file:
for email in emails:
file.write(email + '\n')
print(f"Filtered emails exported to {filename} successfully!")
def main():
domains_input = input("Enter the email domains to filter (comma-separated, e.g., gmail.com,hotmail.com): ")
email_domains = [domain.strip() for domain in domains_input.split(',')]
Tk().withdraw() # Hide the Tkinter root window
input_file = askopenfilename(filetypes=[("Text files", "*.txt")]) # Open file dialog for selecting .txt file
with open(input_file, 'r', encoding='utf-8') as file:
all_emails = file.read().splitlines()
filtered_emails = filter_emails_by_domains(all_emails, email_domains)
output_file = asksaveasfilename(defaultextension=".txt", filetypes=[("Text files", "*.txt")], initialfile=f"{os.path.basename(input_file)}_{email_domains}", initialdir=os.path.dirname(input_file))
if output_file:
export_emails_to_txt(filtered_emails, output_file)
else:
print("Export canceled.")
if __name__ == '__main__':
main()