Created
February 9, 2015 23:57
-
-
Save jchysk/eac3eaaadc9e6b54aa47 to your computer and use it in GitHub Desktop.
Check that domain of email addresses can be resolved
This file contains 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
#!/usr/bin/python | |
""" | |
Takes a csv of email addresses and gives back a csv of the email addresses that have a resolvable domain. | |
""" | |
domains = list() | |
checked = [] | |
checked_bad = [] | |
import socket | |
import csv | |
file = open("good_emails.csv", "wb") | |
count = 0 | |
with open("testfile.csv", "rb") as csvfile: | |
spamwriter = csv.writer(file, delimiter=';', | |
quotechar='|', quoting=csv.QUOTE_NONE) | |
spamreader = csv.reader(csvfile, delimiter=',', quotechar='|') | |
for row in spamreader: | |
for email in row: | |
domain = email.split("@")[1].lower() | |
try: | |
count += 1 | |
if domain in checked: | |
spamwriter.writerow([email + ","]) | |
elif domain in checked_bad: | |
raise Exception | |
else: | |
socket.gethostbyname(domain) | |
spamwriter.writerow([email + ","]) | |
checked.append(domain) | |
if count % 50 == 0: | |
spamwriter.flush() | |
print "successful email is: " + repr(email) + "\n" | |
except: | |
checked_bad.append(domain) | |
print "failed email is: " + repr(email) + "\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment