However, in my quest to read every RTFM I stumbled upon a post regarding Python+REST to access Alexa Web Search. After staring at Python code, especially trying to grapple why SOAP isn't working, updating the outdated REST code was a 5 minute hack. So, if you are interested in using Alexa Web Search with Python via Rest, look below:
websearch.py
#!/usr/bin/python """ Test script to run a WebSearch query on AWS via the REST interface. Written originally by Walter Korman (shaper@wgks.org), based on urlinfo.pl script from AWIS-provided sample code, updated to the new API by Kelvin Nicholson (kelvin@kelvinism.com). Assumes Python 2.4 or greater. """ import base64 import datetime import hmac import sha import sys import urllib import urllib2 AWS_ACCESS_KEY_ID = 'your-access-key' AWS_SECRET_ACCESS_KEY = 'your-super-secret-key' def get_websearch(searchterm): def generate_timestamp(dtime): return dtime.strftime("%Y-%m-%dT%H:%M:%SZ") def generate_signature(operation, timestamp, secret_access_key): my_sha_hmac = hmac.new(secret_access_key, operation + timestamp, sha) my_b64_hmac_digest = base64.encodestring(my_sha_hmac.digest()).strip() return my_b64_hmac_digest timestamp_datetime = datetime.datetime.utcnow() timestamp_list = list(timestamp_datetime.timetuple()) timestamp_list[6] = 0 timestamp_tuple = tuple(timestamp_list) timestamp = generate_timestamp(timestamp_datetime) signature = generate_signature('WebSearch', timestamp, AWS_SECRET_ACCESS_KEY) def generate_rest_url (access_key, secret_key, query): """Returns the AWS REST URL to run a web search query on the specified query string.""" params = urllib.urlencode( { 'AWSAccessKeyId':access_key, 'Timestamp':timestamp, 'Signature':signature, 'Action':'WebSearch', 'ResponseGroup':'Results', 'Query':searchterm, }) return "http://websearch.amazonaws.com/?%s" % (params) # print "Querying '%s'..." % (query) url = generate_rest_url(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, searchterm) # print "url => %s" % (url) print urllib2.urlopen(url).read()
You run it like this:
>>> from websearch import get_websearch >>> get_websearch('python')