import dns.resolver import json # from hunter_helper import companies as comps ''' Input domain Returns 1: guaranteed O365 user 2: possible O365 user 3: non-O365 user 4: no answer ''' def domain_lookup(dom): try: answers = dns.resolver.query(dom, 'MX') except: return 4 flag = 3 for rdata in answers: if 'outlook.com' in str(rdata.exchange): return 1 elif 'gmail' in str(rdata.exchange) or \ 'hotmail' in str(rdata.exchange) or \ 'msoutlookonline' in str(rdata.exchange): continue else: flag=2 return flag def handleDomain(comp): if comp is None: return False res = domain_lookup(comp) if res == 1: return True elif res == 2: return False # can handle differently acc. to need elif res == 3: return False else: return False # def OnO365(csv, domain_index, out): ''' INPUT: csv: path of file to be used domain_index: 0-indexed position of domain in csv out: path of file to which to be written OUTPUT: (writes lines corresponding to comapnies guarateed to be on O365 to designated file) ls ret = [] with open(csv, 'r') as infile: for line in infile: domain = line.split(',')[domain_index].replace('https://','').replace('http://','').split('/')[0] if handleDomain(domain): ret.append(line) with open(out, 'w') as outfile: for line in ret: outfile.write(line + '\n') ''' print('hello')
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question