Created
April 14, 2016 16:55
-
-
Save gregdingle/b26d64d027bbc9e617014f98420b63b5 to your computer and use it in GitHub Desktop.
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
def register_contact(name, email): | |
""" | |
Uses email domain for company name. | |
See https://developers.intercom.io/reference#create-lead | |
""" | |
data = { | |
"name": name, | |
"email": email, | |
} | |
company = get_company(email) | |
if company: | |
data['companies'] = { | |
'id': company, | |
'name': company | |
} | |
return post('contacts', data) | |
def get_company(email): | |
""" | |
Guesses user's company based on email domain. | |
""" | |
domain = email.split('@')[-1] | |
if domain in EMAIL_DOMAIN_BLACKLIST: | |
return None | |
else: | |
# TODO: even better would be to use word segmentation. | |
# see https://pypi.python.org/pypi/wordsegment | |
company = domain.split('.')[0].title() | |
assert len(company) > 0 | |
return company | |
# Copied from | |
# https://github.com/mailcheck/mailcheck/wiki/List-of-Popular-Domains | |
EMAIL_DOMAIN_BLACKLIST = set([ | |
# Default domains included | |
"aol.com", "att.net", "comcast.net", "facebook.com", "gmail.com", "gmx.com", "googlemail.com", | |
"google.com", "hotmail.com", "hotmail.co.uk", "mac.com", "me.com", "mail.com", "msn.com", | |
"live.com", "sbcglobal.net", "verizon.net", "yahoo.com", "yahoo.co.uk", | |
# Other global domains | |
"email.com", "games.com", "gmx.net", "hush.com", "hushmail.com", "icloud.com", "inbox.com", | |
"lavabit.com", "love.com", "outlook.com", "pobox.com", "rocketmail.com", | |
"safe-mail.net", "wow.com", "ygm.com", "ymail.com", "zoho.com", "fastmail.fm", | |
"yandex.com", | |
# United States ISP domains | |
"bellsouth.net", "charter.net", "comcast.net", "cox.net", "earthlink.net", "juno.com", | |
# British ISP domains | |
"btinternet.com", "virginmedia.com", "blueyonder.co.uk", "freeserve.co.uk", "live.co.uk", | |
"ntlworld.com", "o2.co.uk", "orange.net", "sky.com", "talktalk.co.uk", "tiscali.co.uk", | |
"virgin.net", "wanadoo.co.uk", "bt.com", | |
# Domains used in Asia | |
"sina.com", "qq.com", "naver.com", "hanmail.net", "daum.net", "nate.com", "yahoo.co.jp", "yahoo.co.kr", "yahoo.co.id", "yahoo.co.in", "yahoo.com.sg", "yahoo.com.ph", | |
# French ISP domains | |
"hotmail.fr", "live.fr", "laposte.net", "yahoo.fr", "wanadoo.fr", "orange.fr", "gmx.fr", "sfr.fr", "neuf.fr", "free.fr", | |
# German ISP domains | |
"gmx.de", "hotmail.de", "live.de", "online.de", "t-online.de", "web.de", "yahoo.de", | |
# Russian ISP domains | |
"mail.ru", "rambler.ru", "yandex.ru", "ya.ru", "list.ru", | |
# Belgian ISP domains | |
"hotmail.be", "live.be", "skynet.be", "voo.be", "tvcablenet.be", "telenet.be", | |
# Argentinian ISP domains | |
"hotmail.com.ar", "live.com.ar", "yahoo.com.ar", "fibertel.com.ar", "speedy.com.ar", "arnet.com.ar", | |
# Domains used in Mexico | |
"hotmail.com", "gmail.com", "yahoo.com.mx", "live.com.mx", "yahoo.com", "hotmail.es", "live.com", "hotmail.com.mx", "prodigy.net.mx", "msn.com" | |
]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment