Skip to content

Instantly share code, notes, and snippets.

@jugyo
Created August 27, 2008 06:34
Show Gist options
  • Save jugyo/7440 to your computer and use it in GitHub Desktop.
Save jugyo/7440 to your computer and use it in GitHub Desktop.
Amazon ECS Sesarch
import urllib
import cgi
import wsgiref.handlers
import os
from google.appengine.api import urlfetch
from google.appengine.ext.webapp import template
from google.appengine.ext import webapp
class Amazon(webapp.RequestHandler):
def get(self):
template_values = {
'data': '',
'keywords': '',
}
path = os.path.join(os.path.dirname(__file__), 'amazon.html')
self.response.out.write(template.render(path, template_values))
def post(self):
# Keyword
keywords = self.request.get('keywords')
if keywords:
# AWS AccessKey
awsKey = "Your AWS AccessKey"
# Create URL for Amazon ECS
awsUrl = "http://webservices.amazon.co.jp/onca/xml"
awsUrl += "?Service=AWSECommerceService&"
awsUrl += "&AWSAccessKeyId=" + awsKey
awsUrl += "&Operation=ItemSearch"
awsUrl += "&ContentType=text/xml"
awsUrl += "&ResponseGroup=Medium,Images"
awsUrl += "&Page=1"
awsUrl += "&SearchIndex=Books"
awsUrl += "&Keywords=" + keywords
# Ask to Amazon ECS
resData = urlfetch.fetch(awsUrl)
template_values = {
'data': resData.content,
'keywords': keywords,
}
path = os.path.join(os.path.dirname(__file__), 'amazon.html')
self.response.out.write(template.render(path, template_values))
else:
self.redirect(self.request.uri)
def main():
application = webapp.WSGIApplication(
[
('/', Amazon),
],
debug=True)
wsgiref.handlers.CGIHandler().run(application)
if __name__ == "__name__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment