Example

Example

"""
Description: Summarizer 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 url, summarization parameters and API key for authorization purposes (change YourAPIKey to the Intellexer API key)
api_url = "http://api.intellexer.com/summarize?apikey=YourAPIKey&url=http://www.infoplease.com/biography/var/barackobama.html&summaryRestriction=4&returnedTopicsCount=1"

# print response results
def print_response(response):
	print "Document structure: ", response.get('structure')
	topics = response.get('topics')
	print "Document topics: "
	for topic in topics:
		print "\t", topic
	print "Document summary:"
	items = response.get('items')
	for item in items:
		print item.get('text').encode('utf-8')

# create request to the Summarizer 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

Document structure:  NewsArticle
Document topics: 
	Social.politics
Document summary:
Best known as:  President of the United States, 2009-present
Barack Obama is the 44th president of the United States and the first African-American president in American history.
Barack Obama was elected to the Illinois Senate in 1996, and then to the U.S. Senate in 2004, beating Republican candidate Alan Keyes .
Barack Obama published the personal memoir Dreams from My Father  in 1995, and published a second book, The Audacity of Hope , in 2006.