Flask
pip install flask
MongoEngine
pip install mongoengine
WTForms
pip install wtforms
The process consists of 2 parts:
- Set up Flask server to listen for upcoming Full Contact response.
- Send the request to Full Contact.
To set up Flask server, run python flask_fullcontact.py
. By default,
it runs on http://localhost:5000/ and the webhook callback is at http://localhost:5000/webhook/.
When testing, you can use proxylocal (http://proxylocal.com/) to make localhost visible
to the outside world.
To request the Full Contact info about some e-mail(s), you can run the fullcontact.py from terminal, use a batch_lookup function from its API or access the Web API.
Web API consists of 3 functions:
- request contact lookup via /api/ POST message
{'data': [ ['email', 'wojcikstefan@gmail.com'], ['phone', '+48601941311'], ['twitter', 'stefanwojcik'], ['facebookUsername', 'wojcikstefan'] ]}
- get aggregated data for 1 contact via /api/ GET arguments
/api/?email=wojcikstefan@gmail.com,stefan_wojcik@o2.pl&phone=+48601941311&twitter=stefanwojcik&facebookUsername=wojcikstefan
- get a list aggregated data for multiple contacts via /api/get-list/ POST message
{'data': [ [ ['email': 'wojcikstefan@gmail.com'], ['phone': '+48601941311'], ['twitter': 'stefanwojcik'], ['facebookUsername': 'wojcikstefan'] ], [ ['email': 'someotherdude@gmail.com'] ] ]}
The POST requests' content-type should be application/json. For an example how to use Webservice API, check out the test_webservice.py file.
To request the data from the terminal, use python fullcontact.py
with additional arguments.
usage: fullcontact.py [-h] [-w WEBHOOK] [-e EMAILS [EMAILS ...]] [-f FILE] -h, --help show this help message and exit -w WEBHOOK, --webhook webhook URL to a callback for delayed Full Contact API response -e EMAILS [EMAILS ...], --emails EMAILS [EMAILS ...] E-mail addresses to look up -p PHONES [PHONES ...], --phones PHONES [PHONES ...] Phone numbers -t TWITTERS [TWITTERS ...], --twitters TWITTERS [TWITTERS ...] Twitter usernames -fb FACEBOOKS [FACEBOOKS ...], --facebooks FACEBOOKS [FACEBOOKS ...] Facebook usernames -f FILE, --file FILE CSV file with e-mail addresses
Examples:
python fullcontact.py -e address@one.com address@two.com -w url_to_webhook
python fullcontact.py -f csv_with_emails.csv -w url_to_webhook
python fullcontact.py -e address@mail.com -p +13037170414 -fb fb_username -w url_to_webhook
To use the fullcontact.py Low-level API, you use lists of tuples (type, data) for both lookup request and data retrieval from DB.
Type can be have one of the following values:
- 'email'
- 'phone'
- 'twitter'
- 'facebookUsername'
from fullcontact import aggregate_data, batch_lookup
...
data_list = [
('email', 'address@one.com'),
('email', 'address@two.com'),
('phone', '+13037170414'),
('twitter', 'twitter_username'),
('facebookUsername', 'fb_username')
]
# to request separate information about every piece of data (and get logs in return)
response_logs = batch_lookup(data_list, url_to_webhook)
# to get aggregated information about all the pieces of data
userdata = aggregate_data(data_list)
There is a test_webservice.py file included for testing purposes. Before you run it, make sure the Flask server is working and is public via proxylocal
python flask_fullcontact.py
proxylocal 5000 --host fullcontact
python test_webservice.py