def full_contact_request(email): """ Request fullcontact info based on email """ if (constants.FULLCONTACT_KEY is None): logger.fatal("constants.FULLCONTACT_KEY is not set.") return logger.info('Looking up %s', email) fc = FullContact(constants.FULLCONTACT_KEY) r = fc.person(email=email) MIN_RETRY_SECS = 10 MAX_RETRY_SECS = 600 code = int(r.status_code) if (code == 200) or (code == 404): # Success or not found # (We log "not found" results in db too, so that we know # we tried and can move on to next email.) contact_json = r.json() fc_row = db_models.FullContact() fc_row.email = email fc_row.fullcontact_response = contact_json if 'socialProfiles' in contact_json: profiles = contact_json['socialProfiles'] for profile in profiles: if 'typeId' in profile and 'username' in profile: network = profile['typeId'] username = profile['username'] if network == 'angellist': fc_row.angellist_handle = username if network == 'github': fc_row.github_handle = username if network == 'twitter': fc_row.twitter_handle = username try: db.session.add(fc_row) db.session.commit() logger.info('Email %s recorded to fullcontact', email) except IntegrityError as e: logger.warning( "Email %s has already been entered in FullContact table.", email) elif code == 403: # Key fail logger.fatal("constants.FULLCONTACT_KEY is not set or is invalid.") elif code == 202: # We're requesting too quickly, randomly back off delay = randint(MIN_RETRY_SECS, MAX_RETRY_SECS) logger.warning( "Throttled by FullContact. Retrying after random delay of %d" % delay) full_contact_request.retry(countdown=delay) else: logger.fatal("FullContact request %s with status code %s", email, r.status_code) logger.fatal(r.json())
def run(self, conf, args, plugins): fc = FullContact(conf['FullContact']['key']) if args.twitter: res = fc.person(twitter=args.twitter) print(json.dumps(res.json(), sort_keys=True, indent=4)) elif args.email: res = fc.person(email=args.email) print(json.dumps(res.json(), sort_keys=True, indent=4)) elif args.phone: res = fc.person(phone=args.phone) print(json.dumps(res.json(), sort_keys=True, indent=4)) elif args.md5: res = fc.person(emailMD5=args.md5) print(json.dumps(res.json(), sort_keys=True, indent=4)) elif args.domain: res = fc.person(domain=args.domain) print(json.dumps(res.json(), sort_keys=True, indent=4)) else: self.parser.print_help()
def test_invalid_api_keys(self): fc = FullContact('test_key') r = fc.person(email='*****@*****.**') assert_equal(r.status_code, 403) test_batch = [ ('person', {'email': '*****@*****.**'}), ('person', {'name': 'Bob Smith'}) ] r = fc.api_batch(test_batch) assert_equal(r.status_code, 403)
def test_invalid_api_keys(self): fc = FullContact('test_key') r = fc.person(email='*****@*****.**') assert_equal(r.status_code, 403) test_batch = [('person', { 'email': '*****@*****.**' }), ('person', { 'name': 'Bob Smith' })] r = fc.api_batch(test_batch) assert_equal(r.status_code, 403)
def check_fullcontact(self, email, password, interactive_flag=False, elastic=False): print("---" + Fore.CYAN + "FullContact" + Fore.RESET + "---") fc = FullContact(conf['keys']['fullcontact']) person = fc.person(email=email) decoded_person_json = person.content.decode("utf-8") person_json = json.loads(decoded_person_json) social_to_push = [] to_elastic = {"email": email, "password": password} try: if person_json['status'] == 200: if 'contactInfo' in person_json: if 'fullName' in person_json['contactInfo']: print(person_json['contactInfo']['fullName'] ) if 'socialProfiles' in person_json: for social in person_json['socialProfiles']: social_to_push.append(social['url']) print(social['url']) if 'demographics' in person_json: if 'locationGeneral' in person_json['demographics']: print(person_json['demographics']['locationGeneral']) to_elastic.update(person_json) if elastic: self.put_elastic('fullcontact', 'email', to_elastic) elif person_json['status'] == 202: if interactive_flag: time_dec = input("Your search is queued, do you want to wait for 2 minutes? [Y/N] \n> ") if time_dec == "Y": print("Sleeping...") time.sleep(60 * 2) self.check_fullcontact(email, elastic) else: pass else: print("No results") except Exception as e: print(Fore.RED + str(e) + Fore.RESET) if len(social_to_push) > 0 and interactive_flag: return social_to_push else: return False
from fullcontact import FullContact import json fc = FullContact('your_api_key') user_id = input('Please enter user email-id: ') r = fc.person(email=user_id) #data = json.load(r.json()) data = r.json() #print(data['contactInfo']) if data['status'] == 200: print('Name: ' + data['contactInfo']['fullName']) print('Location: ' + data['demographics']['locationDeduced']['deducedLocation']) else: print('Data unavailable right now.')