forked from realpython/python-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
30_fullcontact.py
49 lines (34 loc) · 927 Bytes
/
30_fullcontact.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import sys
import requests
"""
1. pip install requests
2. Obtain an API key: https://www.fullcontact.com/developer/pricing/
Example usage:
$ python 30_fullcontact.py email [email protected]
$ python 30_fullcontact.py twitter TWITTER_HANDLE
"""
# constants
API_KEY = 'GET YOUR OWN'
BASE_URL = 'http://api.fullcontact.com/v2/person.json'
# helpers
def get_arguments():
if len(sys.argv) is 3:
return {
'media': sys.argv[1],
'user_info': sys.argv[2]
}
else:
print('Specify at least 1 argument')
sys.exit()
def call_api(contact):
url = BASE_URL + '?{0}={1}&apiKey={2}'.format(
contact['media'], contact['user_info'], API_KEY)
r = requests.get(url)
if r.status_code == 200:
return r.text
else:
return "Sorry, no results found."
# main
if __name__ == "__main__":
media = get_arguments()
print(call_api(media))