Skip to content

Instantly share code, notes, and snippets.

@skyler
Last active December 18, 2015 17:19
Show Gist options
  • Save skyler/5818130 to your computer and use it in GitHub Desktop.
Save skyler/5818130 to your computer and use it in GitHub Desktop.
"""
Obfuscate any email addresses by replacing their domain name
with something generated.
:author Skyler Slade
"""
import re
import string
import sys
email_pattern = r'.+@([^@\s]+\.[^\s]{2,})'
pattern = re.compile(email_pattern)
if len(sys.argv) < 2:
sys.exit("No file specified")
filename = sys.argv[1]
with open(filename) as file:
i = 0
for line in file:
i += 1
m = pattern.match(line)
if m:
replace = m.groups()[0]
# I gave up checking for this in the regex
if not 'coefficientinc.com' in replace:
new = string.ascii_lowercase[1 % 26] + str(i) + '.web'
print string.replace(line, replace, new),
continue
print line,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment