python - extracting entities of tweets using opencalais -


i have extract entities tweets using tool opencalais. code is:

# code based on: http://www.flagonwiththedragon.com/2011/06/08/dead-simple-python-calls-to-open-calais-api/  import urllib, urllib2  ##### set api key , rest url values.  x-ag-access-token1 = 'o7ttcxv6tfha4z5ekjjxpcrcdwndxl' # calais api key. calaisrest_url = 'https://api.thomsonreuters.com/permid/calais' # older rest interface. # info on newer one: http://www.opencalais.com/documentation/calais-web-service-api/api-invocation/rest  # alert user , shut down if api key variable still null. if x-ag-access-token1 == '':   print "you need set calais api key in 'x-ag-access-token' variable."  import sys  sys.exit()    ##### set text ask calais analyze.  # text from: http://www.usatoday.com/sports/football/nfl/story/2012-03-22/tim-tebow-jets-hoping-to-avoid-controversy/53717542/1 sampletext = ''' millions of football fans, tim tebow caught few training camp glimpses of new york jets during summer of 2010 on hbo's hard knocks. '''  ##### set xml parameters calais.  # see "input parameters" at: http://www.opencalais.com/documentation/calais-web-service-api/forming-api-calls/input-parameters calaisparams = ''' <c:params xmlns:c="http://s.opencalais.com/1/pred/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">  <c:processingdirectives c:contenttype="text/txt"   c:enablemetadatatype="genericrelations,socialtags"   c:outputformat="text/simple"/>  <c:userdirectives/>  <c:externalmetadata/> </c:params> '''  ######################### ##### send data calais api.  # see: http://www.opencalais.com/apicalls datatosend = urllib.urlencode({    'x-ag-access-token': x-ag-access-token1,    'content': sampletext,    'paramsxml': calaisparams })  ##### api results , print them.  results = urllib2.urlopen(calaisrest_url, datatosend).read() print results 

i getting following error:

x-ag-access-token1 = 'o7ttcxv6tfha4z5ekjjxpcrcdwndxl' # calais api key. syntaxerror: can't assign operator. open calais has changed new api.

don't use '-' in variable assignment, use '_' because otherwise python interprets minus sign , throws 'syntaxerror: can't assign operator' . make sure using latest api opencalais. try simple test:

>>> my-var = 'hello world' file "<stdin>", line 1 syntaxerror: can't assign operator 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -