class HunterioManager: def __init__(self): self.hunter = PyHunter('72ebe102b85923275c17d6b374551edb56dbb898') def get_mails(self, domain, company): """ Wrapper around domain_search """ results_file = domain + ".txt" try: if company != "": print(company) x = self.hunter.domain_search(company=company) else: print(domain) x = self.hunter.domain_search(domain) #json.dumps(json_data["data"]) with open(results_file, 'w') as file: #x="{'domain': 'instagram.com', 'disposable': False, 'webmail': False, 'pattern': '{first}{last}', 'organization': 'Instagram', 'emails': [{'value': '*****@*****.**'}]}" #file.write(x) ==> not working for i in x['emails']: print(i['value']) except Exception as e: raise e print("Go to hunter.io/<domain> and explore the results manually")
def search(self): hunter = PyHunter(self.apikey) result = hunter.domain_search(company=self.domain, limit=self.limit, emails_type='personal') return result
def verify_email(email): hunter = PyHunter(os.environ.get('HUNTER_API_KEY')) try: quality_score = hunter.email_verifier(email) except HunterApiError: return 0 return quality_score.get('score', 0)
def domain_search_hunter(self): if len(self.hunter_io_mails) > 0: self.email_list.update(self.hunter_io_mails) print( "Email list is expanded using hunter.io results from the file." ) return hunter = PyHunter(self.hunter_api_key) i = 0 search = hunter.domain_search(self.domain_name, limit=100, offset=100 * i) while search['emails']: search = hunter.domain_search(self.domain_name, limit=100, offset=100 * i) for item in search['emails']: user_mail = item['value'] self.email_list.add(user_mail) self.hunter_io_mails.append(user_mail) i += 1 print("{} emails have been found via hunter.io".format( len(self.hunter_io_mails))) with open("email_hunter.em", "w", encoding="UTF-8") as ff: ff.write("\n".join(self.hunter_io_mails))
def validate_email(self, email): hunter_key = 'HUNTER_API_KEY' hunter = PyHunter(hunter_key) if hunter.email_verifier(email)['status'] not in ['valid','webmail']: raise serializers.ValidationError('Invalid email address') return email
def hunter_domain_search(domain): api = "44ac9d0fcf060465933c1591d75c2ace4b1692d8" hunter = PyHunter(api) info = (hunter.account_information()) print("Kalan API Hakkı : ",info["calls"]["left"]) print("hunter domain search..") while(True): if (info["calls"]["left"] != 0): result = hunter.domain_search(domain) result = result["emails"] for i in range(len(result)): email.append(result[i]["value"]) break else: print("\nMevcut Api Arama Hakkı Bitti") print(""" 1 - Yeni API Ekle 0 - Çıkış Yap """) choise = input("Yapmak İstediğiniz İşlemi Seçiniz = ") if (choise == "1"): api = input("\nYeni Api Değerini Giriniz = ") elif (choise == "0"): break else: print("Hatalı Bir Seçim Yaptınız, Tekrar Deneyiniz..")
def create(self, request, *args, **kwargs): #check email by EmailHunter #if it's failed, send status 400 hunter = PyHunter(EMAIL_HUNTER_API_KEY) verify = hunter.email_verifier(request.data['email']) if verify.get('result', {}) == 'undelivarable': return Response(status=status.HTTP_400_BAD_REQUEST) #enrich account by first name and last name using clearbit clearbit.key = CLEARBIT_APY_KEY res = clearbit.Enrichment.find(email=request.data['email']) try: request.data['first_name'] = res['person']['name'].get( 'givenName', '') request.data['last_name'] = res['person']['name'].get( 'familyName', '') except (TypeError, KeyError): #if enrichment is failed, set fields as empty strings request.data['first_name'] = request.data['last_name'] = '' #serialize data from request serializer = self.get_serializer(data=request.data) serializer.is_valid(raise_exception=True) #and create a user self.perform_create(serializer) #define headers and respond to client headers = self.get_success_headers(serializer.data) return Response(serializer.data, status=status.HTTP_201_CREATED, headers=headers)
def check_email_function(user_id): user = User.objects.get(pk=user_id) hunter = PyHunter(settings.PYHUNTER_TOKEN) res = hunter.email_verifier(user.email) # check result parameters here if res['score'] > 10: user.is_active = True user.save()
def check_email(email): # Check the deliverability of a given email adress by emailhunter.co hunter = PyHunter(settings.EMAILHUNTER_API_KEY) hunter_result = hunter.email_verifier(email) if hunter_result and 'result' in hunter_result: return hunter_result['result'] else: return 'unchecked'
def register(usr): hunter = PyHunter(config("HUNTER_KEY")) mail = hunter.email_verifier(usr["email"])["webmail"] if mail: user = models.User() user.first_name = usr["first_name"] user.last_name = usr["last_name"] user.email = usr["email"] user.password = md5(usr["password"].encode()).hexdigest() user.save()
def validate_email(self, value): """ Check if email exists """ if not settings.DEBUG_SIGNUP: hunter = PyHunter(settings.HUNTER_API_KEY) verification = hunter.email_verifier(value) if verification['result'] == 'undeliverable': raise ValidationError('Email address does not exist') return value
def validate_email(value): # Use emailhunter.co for verifying email existence on signup py_hunter = PyHunter(settings.HUNTER_API_KEY) if settings.HUNTER_ENABLED and settings.HUNTER_API_KEY: if py_hunter.email_verifier(value).get( 'result') != 'undeliverable': return value raise serializers.ValidationError( 'An issue with email verification occures') return value
def validate_email(self, email): hunter = PyHunter(HUNTERIO_KEY) try: payload = hunter.email_verifier(email) except Exception: return result = payload.get('result') if result == 'undeliverable': raise serializers.ValidationError( 'The email address is not valid.')
def emailVerifier(email): print("email trouvé: ", email) if email == None: return False else: hunter = PyHunter('a890302fd13f718af83604989dbd3213772a0d07') statut = hunter.email_verifier(email)['result'] print("statut: ", statut) if statut == 'undeliverable': return False else: return True
def _mail_verification(mail): """Mail validation via hunter site""" try: hunter = PyHunter(my_hunter_api_key) user_data = hunter.email_verifier(mail) # On risky & deliverable continue if user_data['result'] == 'undeliverable': raise Exception('Mail not approved') return user_data except Exception as e: logging.warning(e) return {e}
def hunter(first_name, last_name, company_name, API): hunter = PyHunter(API) email = "" score = 0 email, score = hunter.email_finder(first_name=first_name, last_name=last_name, company=company_name) if type(email) != type(""): email = 'PERSON NOT FOUND' print('PERSON NOT FOUND') if type(score) != type(0): score = -1 return email, score
def register(): if request.method == "POST": email = request.form['email'] # checks if email exists in database user = User.query.filter_by(email=email).first() if not user: email_db = '' else: email_db = user.email if email != email_db: try: # validate email using hunter hunter = PyHunter('fce98eff8d99f93fe14df75bf06d0713d73f406a') hunter.email_verifier(email) # gets additional information for a user using clearbit clearbit.key = 'sk_074ad5265e753838e4bc9993b1a1473f' person = clearbit.Person.find(email=email, stream=True) bio = None if person is not None and person['bio'] is not None: bio = person['bio'] role = None if person is not None and person['employment']['role'] is not None: role = person['employment']['role'] location = None if person is not None and person['location'] is not None: location = person['location'] # inserts new user into database new_user = User(public_id=str(uuid.uuid4()), first_name=request.form['first_name'], last_name=request.form['last_name'], email=email, password=request.form['password'], bio=bio, role=role, location=location) db.session.add(new_user) db.session.commit() return render_template('login.html') except: return render_template('invalid.html') else: return render_template('userexists.html') return render_template('register.html')
def email_finder(company, name): print ('domain name found by clearbit:', company) if company is not None : '''You can also use the company name and the full name instead, along with raw to get the full response:''' hunter = PyHunter('a890302fd13f718af83604989dbd3213772a0d07') json_load = json.loads(hunter.email_finder(company= company, full_name= name, raw = True).text) email = json_load['data']['email'] score = json_load['data']['score'] position = json_load['data']['position'] first_name = json_load['data']['first_name'] last_name = json_load['data']['last_name'] return email, score, position, first_name, last_name else: return None, None, None, None, None
def domain_search(company, qualified): if company is not None: hunter = PyHunter('a890302fd13f718af83604989dbd3213772a0d07') json_load = json.loads(hunter.domain_search(company=company, limit=1000, raw = True).text) positions = [] emails = [] last_names = [] first_names = [] scores = [] companies = [] for i in range(len(json_load['data']['emails'])): if emailVerifier(json_load['data']['emails'][i]['value']) == True: if qualified is False: positions.append(json_load['data']['emails'][i]['position']) emails.append(json_load['data']['emails'][i]['value']) scores.append(json_load['data']['emails'][i]['confidence']) last_names.append(json_load['data']['emails'][i]['last_name']) first_names.append(json_load['data']['emails'][i]['first_name']) companies.append(company) if qualified is True: if json_load['data']['emails'][i]['last_name'] is not None: positions.append(json_load['data']['emails'][i]['position']) emails.append(json_load['data']['emails'][i]['value']) scores.append(json_load['data']['emails'][i]['confidence']) last_names.append(json_load['data']['emails'][i]['last_name']) first_names.append(json_load['data']['emails'][i]['first_name']) companies.append(company) if qualified is 'ultra': if json_load['data']['emails'][i]['position'] is not None: positions.append(json_load['data']['emails'][i]['position']) emails.append(json_load['data']['emails'][i]['value']) scores.append(json_load['data']['emails'][i]['confidence']) last_names.append(json_load['data']['emails'][i]['last_name']) first_names.append(json_load['data']['emails'][i]['first_name']) companies.append(company) print('company name terminée: ', company) companies = pd.DataFrame({ 'last_name': last_names, 'email': emails, 'company': companies, 'position': positions, 'first_name': first_names, 'score': scores }) if emails != []: if qualified is False: companies.to_csv('/home/francois/Téléchargements/allCompanies/' + company + '.csv') if qualified is True: companies.to_csv('/home/francois/Téléchargements/allCompanies/' + company + '.csv') if qualified is 'ultra': companies.to_csv('/home/francois/Téléchargements/allCompanies/' + company + '.csv')
def check_email_hunter(email): try: # we could also use hunter.email_finder for get email list from domain and check is it include our email or not, # but I see that we don't get all emails using this function and I decide dont't use it verified = False hunter = PyHunter(settings.HUNTERIO_API_KEY) result = hunter.email_verifier(email) if isinstance(result, dict) and result.get( 'webmail', False) and not result.get('block', True): verified = True except (ConnectionError, Timeout, HTTPError) as ex: logger.error(f'Email hunter connection error {ex}') return verified
def verifylist(): for x in EMAILS: list = EMAILS hk = API_KEYS["hunter"] hunter = PyHunter(hk) h = hunter.email_verifier(x) if h["result"] == "undeliverable": Style.Colors.RB(x + " EMAIL RETURNED AN UNDELIVERABLE!") continue break else: Style.Colors.GB(x + " " + h["result"]) continue break
def get_email(row): hunter = PyHunter(os.environ.get('HUNTER_API_KEY')) suggested_email = None confidence_score = None try: suggested_email, confidence_score = hunter.email_finder( company=row['employeecompany'], first_name=row['firstname'], last_name=row['lastname']) except HTTPError: pass if confidence_score is not None and confidence_score > CONFIDENCE_THRESHOLD: return suggested_email else: return None
def __init__(self): super(MailEvaluator, self).__init__() # Testing if all mandatories variables for the Mail evaluator are correctly set in the config.ini mandatories_cfg_vars = ['LINKEDIN_LOGIN', 'LINKEDIN_PASSWD', 'LINKEDIN_SECONDS_WAITING_BETWEEN_TWO_SCRAPS'] Oss117.check_mandatories_var_in_config_file("EVALUATORS", mandatories_cfg_vars, self.logger) try: # The neverbounce library https://github.com/NeverBounce/NeverBounceApi-Python self.neverbounce_client = neverbounce_sdk.client(api_key=setting.config["EVALUATORS"]["NEVERBOUNCE_KEY"]) self.hunterio = PyHunter(setting.config["EVALUATORS"]["HUNTERIO_KEY"]) except AttributeError: self.logger.error("Please specify you API key in your setting file (NeverBounce, hunter.io) to use Mail validators") exit(1)
def Text(self): textboxValue = self.textbox.text() hunter=PyHunter('Enter key here') Temp=hunter.domain_search(textboxValue) Temp1=Temp['emails'] for i in range (0,len(Temp1)): temp2=Temp1[i] Dom_em=temp2['value'] file = open(textboxValue + ".txt",'w') for i in range (0,len(Temp1)): temp2=Temp1[i] file.write(temp2['value']) file.write('\n') QMessageBox.question(self, 'Emails', "The Emails are saved in a text file " , QMessageBox.Ok, QMessageBox.Ok) file.close()
def create(self, validated_data): user = User( email=validated_data['email'], first_name=validated_data['first_name'], last_name=validated_data['last_name'] ) user.set_password(validated_data['password']) user.is_active = True hunter = PyHunter(settings.HUNTER_API_KEY) hunter.email_verifier(user.email) pp = pprint.PrettyPrinter(indent=4) pp.pprint(hunter.email_verifier(user.email)) user.save() return user
def api_call(self): # request Api emailhunter.co hunter_key = '0951ac6a0348e8db1a20fe321c1995aa0bc48bfa' try: email_status = PyHunter(hunter_key).email_verifier( self.request.data['email'])['result'] print('email_status', email_status) except: return Response('Not valid mailbox', status=status.HTTP_406_NOT_ACCEPTABLE) if email_status == 'undeliverable': return Response( 'Email undeliverable please provide exists mailbox', status=status.HTTP_406_NOT_ACCEPTABLE) # request Api clearbit.com clearbit.key = 'sk_00c36392dc89fb53f371529b79e7b4f4' try: response = clearbit.Enrichment.find( email=self.request.data['email'], stream=True) except: response = None # get location only city_data = {} if not response: city_data['city'] = 'not response' elif response.get('person') is not None: city_data['city'] = response['person']['location'] return city_data
def email_verify(email): """ Check is email valid and is it deliverable :param email: email to check :return: True if email valid :raise ValidationError if email invalid or undeliverable """ hunter = PyHunter(settings.HUNTER_API_KEY) try: response = hunter.email_verifier(email) if response['result'] == 'undeliverable': raise serializers.ValidationError except exceptions.HTTPError: raise serializers.ValidationError return True
def post(self, request, format=None): hunterAPI = '5aa57f6c3b4600d3a881a0d2b38e9311e5b91640' email = request.data.get('email') hunter = PyHunter(hunterAPI) verify_email = hunter.email_verifier(email) #Checks if the email is deliverable or not through hunterAPI if(verify_email.get('result')=='undeliverable'): return Response({'status': 'Incorrect data', 'message': 'E-mail not deliverable'}, status=status.HTTP_400_BAD_REQUEST) else: if not request.data._mutable: request.data._mutable = True serializer = self.serializer_class(data=request.data) if serializer.is_valid(): serializer.save() return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def find_email(self, name, d_name): # creating a hunter object hunter = PyHunter(self.key) #proper capitalization of the name name = " ".join([i.capitalize() for i in name.split(" ")]) #calling api to fetch email and confidency score try: email, c_score = hunter.email_finder(domain=d_name, full_name=name) #rasing exception when non type in returned if email == None: raise ValueError except BaseException: email, c_score = ('NotFound', 0) return email, c_score
def domain_search_hunter(self): hunter = PyHunter(self.hunter_api_key) i = 0 search = hunter.domain_search(self.domain_name, limit=100, offset=100 * i) while search['emails']: search = hunter.domain_search(self.domain_name, limit=100, offset=100 * i) for item in search['emails']: user_mail = item['value'] self.email_list.add(user_mail) self.hunter_io_mails.append(user_mail) i += 1 print("{} emails have been found via hunter.io".format( len(self.hunter_io_mails)))