Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add google appengine support

  • Loading branch information...
commit ac921a8c9586f20fac473e9b9c9044a86b417b8a 1 parent 9116449
Chen Liu authored
6 amazonapi/request.py
@@ -18,9 +18,9 @@ class AWSRequest:
18 18
19 19 ENDPOINT = "http://aws.amazonaws.com/onca/xml"
20 20 SERVICE = "AWSECommerceService"
21   - AWSSECURITYKEY = "SECURITYKEY"
22   - AWSACCESSID = "ACCESSID"
23   - AWSASSOCIATEID = "ASSOCIATEID"
  21 + AWSSECURITYKEY = "SecurityKey"
  22 + AWSACCESSID = "AccessId"
  23 + AWSASSOCIATEID = "personalprice-20"
24 24
25 25 def __init__(self, operation = "", params = None, accesskeyid = None, associatetag = None):
26 26 self.params = {}
10 app.yaml
... ... @@ -0,0 +1,10 @@
  1 +application: price-tracker-poller
  2 +version: 1
  3 +runtime: python27
  4 +api_version: 1
  5 +threadsafe: no
  6 +
  7 +
  8 +handlers:
  9 +- url: /.*
  10 + script: pricetrackersrv.py
9 pricetracker.py
@@ -6,6 +6,7 @@
6 6
7 7 import sys
8 8 import json
  9 +import logging
9 10
10 11 from amazonapi.request import ItemLookUpRequest
11 12 from amazonapi.response import AWSResponse
@@ -80,14 +81,17 @@ def get_response(self):
80 81 response.get_discount()
81 82 response.get_item_info()
82 83 if(self.min_discount != None and self.min_discount > response.responsedict.get("Discount", 0)):
  84 + logging.debug(self.min_discount)
83 85 response.responsedict["match"] = False
84 86 else:
85 87 maxp = sys.maxint
86 88 if(self.max_price != None):
87 89 maxp = self.max_price + 1
  90 + logging.debug(maxp)
88 91 minp = -1
89 92 if(self.min_price != None):
90 93 minp = self.min_price - 1
  94 + logging.debug(minp)
91 95 p = min(response.responsedict.get("Price(New)", sys.maxint), response.responsedict.get("Price(Used)", sys.maxint))
92 96 if(minp < p < maxp):
93 97 response.responsedict["match"] = True
@@ -98,6 +102,11 @@ def get_response(self):
98 102 def get_json_response(self):
99 103 return json.dumps(self.get_response().responsedict)
100 104
  105 +def handle_single_request(asin, maxprice = None, minprice = None, mindiscount = None):
  106 + request = PriceTrackRequest(asin, maxprice, minprice, mindiscount)
  107 + response = request.get_response()
  108 + return json.dumps(response.dump_result())
  109 +
101 110 if __name__ == '__main__':
102 111 request = PriceTrackRequest("B000PFLKAY", 200000, 0, 10)
103 112 response = request.get_response()
36 pricetrackersrv.py
... ... @@ -0,0 +1,36 @@
  1 +'''
  2 +Created on Jan 9, 2012
  3 +
  4 +@author: chenliu
  5 +'''
  6 +
  7 +from google.appengine.ext import webapp
  8 +from google.appengine.ext.webapp.util import run_wsgi_app
  9 +from pricetracker import handle_single_request
  10 +
  11 +class SingleRequestHandler(webapp.RequestHandler):
  12 + def get(self):
  13 + self.response.headers['Content-Type'] = 'application/json'
  14 + asin = self.request.get("asin")
  15 + maxprice = self.request.get("maxprice", None)
  16 + if(maxprice != None):
  17 + maxprice = int(float(maxprice) * 100)
  18 + minprice = self.request.get("minprice", None)
  19 + if(minprice != None):
  20 + minprice = int(float(minprice) * 100)
  21 + mindiscount = self.request.get("mindiscount", None)
  22 + if(mindiscount != None):
  23 + mindiscount = int(mindiscount)
  24 + data = handle_single_request(asin, maxprice, minprice, mindiscount)
  25 + self.response.out.write(data)
  26 +
  27 +application = webapp.WSGIApplication(
  28 + [
  29 + ('/singlerequest', SingleRequestHandler)],
  30 + debug = True)
  31 +
  32 +def main():
  33 + run_wsgi_app(application)
  34 +
  35 +if __name__ == '__main__':
  36 + main()

0 comments on commit ac921a8

Please sign in to comment.
Something went wrong with that request. Please try again.