Last active
December 18, 2015 17:19
-
-
Save skyler/5818130 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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