Created
August 27, 2008 06:34
-
-
Save jugyo/7440 to your computer and use it in GitHub Desktop.
Amazon ECS Sesarch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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