Example
"""
Description: Comparator API usage example.
Copyright: (C) 2016 EffectiveSoft Ltd. All Rights Reserved.
Technical support: technical-support@effective-soft.com
"""
import json
import urllib
import urllib2
# set the URL for GET request, specify comparison urls and API key for authorization purposes (change YourAPIKey to the Intellexer API key)
api_url = "http://api.intellexer.com/compareUrls?apikey=YourAPIKey&url1=http://www.infoplease.com/biography/var/barackobama.html&url2=http://millercenter.org/president/biography/obama-life-in-brief&useCache=false"
# print response results
def print_response(response):
print "Proximity between"
print response.get('document1').get('title'), " and ", response.get('document2').get('title'), " is ", response.get('proximity')
# create request to the Comparator API service
def request_api(url):
req = urllib2.Request(url, None)
conn = urllib2.urlopen(req)
try:
json_response = json.loads(conn.read())
finally:
conn.close()
print_response(json_response)
# perform the request
try:
request_api(api_url)
except urllib2.HTTPError as error:
print 'HTTP error - %s' % error.read()
Output
Proximity between
barackobama.html.html and obama-life-in-brief.html is 0.638202886509