· 6 years ago · Dec 04, 2019, 03:34 PM
1# Zerobounce Request API
2#
3# Make a request to validate your email below.
4#
5#
6# Importing the libraries
7import requests
8import json
9import pandas as pd
10# Setting up the target url
11target_url = 'https://api.zerobounce.net/v2/validate'
12
13stop_validation = False
14end_dataframe = pd.DataFrame()
15
16# Setting up the API key
17api_key = raw_input('Type in your api key: ')
18
19while not stop_validation:
20 # Setting up the email to validate
21 email_to_validate = raw_input('Type in the email to validate: ') # set email between quotes
22 # Setting up the ip address
23 ip_address = raw_input('Type in the ip address: ')
24 # Setting up the request part
25 params_for_url = {'email':email_to_validate, 'api_key':api_key, 'ip_address':ip_address}
26 # Getting the response for the http request
27 response = requests.get(target_url, params=params_for_url)
28 # Making a dictionary to save the result for a dataframe
29 validated = json.loads(response.content)
30 # Importing Pandas for dataframe
31 # Makinga a dataframe out of the result
32 index_for_dataframe = []
33 for key in validated:
34 index_for_dataframe.append(key)
35 result_validate = pd.DataFrame(validated, index=['Validated'])
36
37 if len(end_dataframe.columns) == 0:
38 end_dataframe = result_validate
39 else:
40 end_dataframe = end_dataframe.append(result_validate, ignore_index=True)
41
42 want_to_stop = raw_input('Do you want to stop? y or n')
43 while True:
44 if want_to_stop == 'y' or want_to_stop == 'n':
45 break
46 want_to_stop = raw_input('Do you want to stop? y or n : ')
47
48 if want_to_stop == 'y':
49 stop_validation = False
50 break
51
52print(end_dataframe)
53end_dataframe.to_csv('api_results.csv', index=False)