# download a csv file from the mixpanel portal here: # https://mixpanel.com/project/2667276/view/3204508/app/boards#id=5168849&edited-bookmark=KdaZirXsTSd3 import re import csv import sys from collections import defaultdict # Check if filename was provided as command line argument if len(sys.argv) != 2: print("Usage: python check_new_users.py ") sys.exit(1) GOOD = 0 BAD = 0 # Load emails from CSV file using command line argument emails = [] domains = defaultdict(int) with open(sys.argv[1]) as csvfile: reader = csv.reader(csvfile) next(reader) # Skip header row if present emails = [row[1] for row in reader] # Get second column regexes = { "regex1": r"[a-z]{7}[0-9]{4}[a-z]{1}@(outlook|hotmail)\.com", "regex2": r"[a-z]{5}[0-9]{5}@(outlook|hotmail)\.com", } legitimate_outlook = [ e for e in emails if "@outlook.com" in e ] for label, regex in regexes.items(): GOOD = 0 BAD = 0 for email in emails: if re.match(regex, email): BAD += 1 if email in legitimate_outlook: legitimate_outlook.remove(email) else: GOOD += 1 print(f"{str(regex)} GOOD: {GOOD}, BAD: {BAD}") print(f"\nLegitimate outlook emails: {len(legitimate_outlook)}\n") for email in emails: try: domains[email.split("@")[1]] += 1 except Exception as e: domains["phone"] += 1 # Sort domains by value (count) in descending order and get top 20 sorted_domains = dict(sorted(domains.items(), key=lambda x: x[1], reverse=True)[:10]) for domain, count in sorted_domains.items(): print(f"{domain:26} {count:8}")