Permalink
Browse files

Add google appengine support

  • Loading branch information...
1 parent 9116449 commit ac921a8c9586f20fac473e9b9c9044a86b417b8a @chenliu committed Jan 10, 2012
Showing with 58 additions and 3 deletions.
  1. +3 −3 amazonapi/request.py
  2. +10 −0 app.yaml
  3. +9 −0 pricetracker.py
  4. +36 −0 pricetrackersrv.py
View
6 amazonapi/request.py
@@ -18,9 +18,9 @@ class AWSRequest:
ENDPOINT = "http://aws.amazonaws.com/onca/xml"
SERVICE = "AWSECommerceService"
- AWSSECURITYKEY = "SECURITYKEY"
- AWSACCESSID = "ACCESSID"
- AWSASSOCIATEID = "ASSOCIATEID"
+ AWSSECURITYKEY = "SecurityKey"
+ AWSACCESSID = "AccessId"
+ AWSASSOCIATEID = "personalprice-20"
def __init__(self, operation = "", params = None, accesskeyid = None, associatetag = None):
self.params = {}
View
10 app.yaml
@@ -0,0 +1,10 @@
+application: price-tracker-poller
+version: 1
+runtime: python27
+api_version: 1
+threadsafe: no
+
+
+handlers:
+- url: /.*
+ script: pricetrackersrv.py
View
9 pricetracker.py
@@ -6,6 +6,7 @@
import sys
import json
+import logging
from amazonapi.request import ItemLookUpRequest
from amazonapi.response import AWSResponse
@@ -80,14 +81,17 @@ def get_response(self):
response.get_discount()
response.get_item_info()
if(self.min_discount != None and self.min_discount > response.responsedict.get("Discount", 0)):
+ logging.debug(self.min_discount)
response.responsedict["match"] = False
else:
maxp = sys.maxint
if(self.max_price != None):
maxp = self.max_price + 1
+ logging.debug(maxp)
minp = -1
if(self.min_price != None):
minp = self.min_price - 1
+ logging.debug(minp)
p = min(response.responsedict.get("Price(New)", sys.maxint), response.responsedict.get("Price(Used)", sys.maxint))
if(minp < p < maxp):
response.responsedict["match"] = True
@@ -98,6 +102,11 @@ def get_response(self):
def get_json_response(self):
return json.dumps(self.get_response().responsedict)
+def handle_single_request(asin, maxprice = None, minprice = None, mindiscount = None):
+ request = PriceTrackRequest(asin, maxprice, minprice, mindiscount)
+ response = request.get_response()
+ return json.dumps(response.dump_result())
+
if __name__ == '__main__':
request = PriceTrackRequest("B000PFLKAY", 200000, 0, 10)
response = request.get_response()
View
36 pricetrackersrv.py
@@ -0,0 +1,36 @@
+'''
+Created on Jan 9, 2012
+
+@author: chenliu
+'''
+
+from google.appengine.ext import webapp
+from google.appengine.ext.webapp.util import run_wsgi_app
+from pricetracker import handle_single_request
+
+class SingleRequestHandler(webapp.RequestHandler):
+ def get(self):
+ self.response.headers['Content-Type'] = 'application/json'
+ asin = self.request.get("asin")
+ maxprice = self.request.get("maxprice", None)
+ if(maxprice != None):
+ maxprice = int(float(maxprice) * 100)
+ minprice = self.request.get("minprice", None)
+ if(minprice != None):
+ minprice = int(float(minprice) * 100)
+ mindiscount = self.request.get("mindiscount", None)
+ if(mindiscount != None):
+ mindiscount = int(mindiscount)
+ data = handle_single_request(asin, maxprice, minprice, mindiscount)
+ self.response.out.write(data)
+
+application = webapp.WSGIApplication(
+ [
+ ('/singlerequest', SingleRequestHandler)],
+ debug = True)
+
+def main():
+ run_wsgi_app(application)
+
+if __name__ == '__main__':
+ main()

0 comments on commit ac921a8

Please sign in to comment.