| Line 36... |
Line 36... |
| 36 |
params['ExcludeMe']='true'
|
36 |
params['ExcludeMe']='true'
|
| 37 |
params.update(extra_data)
|
37 |
params.update(extra_data)
|
| 38 |
request_description = '&'.join(['%s=%s' % (k, urllib.quote(params[k], safe='-_.~').encode('utf-8')) for k in sorted(params)])
|
38 |
request_description = '&'.join(['%s=%s' % (k, urllib.quote(params[k], safe='-_.~').encode('utf-8')) for k in sorted(params)])
|
| 39 |
signature = self.calc_signature(method, request_description)
|
39 |
signature = self.calc_signature(method, request_description)
|
| 40 |
url = '%s%s?%s&Signature=%s' % (self.domain, self.uri, request_description, urllib.quote(signature))
|
40 |
url = '%s%s?%s&Signature=%s' % (self.domain, self.uri, request_description, urllib.quote(signature))
|
| - |
|
41 |
print url
|
| 41 |
#headers = {'User-Agent': 'AmazonJavascriptScratchpad/1.0 (Language=Python)'}
|
42 |
#headers = {'User-Agent': 'AmazonJavascriptScratchpad/1.0 (Language=Python)'}
|
| 42 |
#headers.update(kwargs.get('extra_headers', {}))
|
43 |
#headers.update(kwargs.get('extra_headers', {}))
|
| 43 |
response = request(method, url)
|
44 |
response = request(method, url)
|
| 44 |
if action=='GetLowestOfferListingsForSKU':
|
45 |
if action=='GetLowestOfferListingsForSKU':
|
| 45 |
return self.parse_competitor_pricing_response(response)
|
46 |
return self.parse_competitor_pricing_response(response)
|
| 46 |
elif action=='GetMyPriceForSKU':
|
47 |
elif action=='GetMyPriceForSKU':
|
| 47 |
return self.parse_my_pricing_response(response)
|
48 |
return self.parse_my_pricing_response(response)
|
| 48 |
elif action=='GetProductCategoriesForSKU':
|
49 |
elif action=='GetProductCategoriesForSKU':
|
| 49 |
return self.parse_product_category_for_sku(response)
|
50 |
return self.parse_product_category_for_sku(response)
|
| - |
|
51 |
elif action=='GetMatchingProductForId':
|
| - |
|
52 |
return self.parse_product_attributes(response)
|
| 50 |
else:
|
53 |
else:
|
| 51 |
raise
|
54 |
raise
|
| 52 |
|
55 |
|
| 53 |
def parse_product_category_for_sku(self,response):
|
56 |
def parse_product_category_for_sku(self,response):
|
| 54 |
browseNodes = []
|
57 |
browseNodes = []
|
| Line 63... |
Line 66... |
| 63 |
for browsingNode in browsingNodes:
|
66 |
for browsingNode in browsingNodes:
|
| 64 |
temp.append(browsingNode.firstChild.nodeValue)
|
67 |
temp.append(browsingNode.firstChild.nodeValue)
|
| 65 |
browseNodes.append(temp)
|
68 |
browseNodes.append(temp)
|
| 66 |
return browseNodes
|
69 |
return browseNodes
|
| 67 |
|
70 |
|
| - |
|
71 |
def parse_product_attributes(self,response):
|
| - |
|
72 |
spString = re.sub('<\?.*\?>','',response.text)
|
| - |
|
73 |
spString = "<dom>" + spString + "</dom>"
|
| - |
|
74 |
dom = parseString(spString)
|
| - |
|
75 |
sku = dom.getElementsByTagName("GetMatchingProductForIdResult")[0].attributes.items()[2][1]
|
| - |
|
76 |
dimensions = dom.getElementsByTagName("ns2:PackageDimensions")
|
| - |
|
77 |
for dimension in dimensions:
|
| - |
|
78 |
height = dimension.getElementsByTagName("ns2:Height")[0].firstChild.nodeValue #Inch
|
| - |
|
79 |
length = dimension.getElementsByTagName("ns2:Length")[0].firstChild.nodeValue #Inch
|
| - |
|
80 |
width = dimension.getElementsByTagName("ns2:Width")[0].firstChild.nodeValue #Inch
|
| - |
|
81 |
weight = dimension.getElementsByTagName("ns2:Weight")[0].firstChild.nodeValue #Pounds
|
| - |
|
82 |
return {'sku':sku,'length':length,'width':width,'height':height,'weight':weight}
|
| - |
|
83 |
|
| - |
|
84 |
|
| 68 |
def parse_competitor_pricing_response(self,response):
|
85 |
def parse_competitor_pricing_response(self,response):
|
| 69 |
spString = re.sub('<\?.*\?>','',response.text)
|
86 |
spString = re.sub('<\?.*\?>','',response.text)
|
| 70 |
spString = "<dom>" + spString + "</dom>"
|
87 |
spString = "<dom>" + spString + "</dom>"
|
| 71 |
dom = parseString(spString)
|
88 |
dom = parseString(spString)
|
| 72 |
skuOffers = dom.getElementsByTagName('GetLowestOfferListingsForSKUResult')
|
89 |
skuOffers = dom.getElementsByTagName('GetLowestOfferListingsForSKUResult')
|
| Line 228... |
Line 245... |
| 228 |
def get_product_category_for_sku(self, marketplaceid, sku):
|
245 |
def get_product_category_for_sku(self, marketplaceid, sku):
|
| 229 |
data = dict(SellerId=self.merchant_id, MarketplaceId=marketplaceid)
|
246 |
data = dict(SellerId=self.merchant_id, MarketplaceId=marketplaceid)
|
| 230 |
data['SellerSKU'] = sku
|
247 |
data['SellerSKU'] = sku
|
| 231 |
return self.make_request(data,'GetProductCategoriesForSKU')
|
248 |
return self.make_request(data,'GetProductCategoriesForSKU')
|
| 232 |
|
249 |
|
| - |
|
250 |
def get_product_attributes_for_sku(self, marketplaceid, skus):
|
| - |
|
251 |
data = dict(SellerId=self.merchant_id, MarketplaceId=marketplaceid)
|
| - |
|
252 |
num=0
|
| - |
|
253 |
for sku in skus:
|
| - |
|
254 |
data['IdList.Id.%d' % (num + 1)] = sku
|
| - |
|
255 |
num+=1
|
| - |
|
256 |
data['IdType'] = 'SellerSKU'
|
| - |
|
257 |
print data
|
| - |
|
258 |
return self.make_request(data,'GetMatchingProductForId')
|
| - |
|
259 |
|
| 233 |
|
260 |
|
| 234 |
def main():
|
261 |
def main():
|
| 235 |
p = Products("AKIAII3SGRXBJDPCHSGQ", "B92xTbNBTYygbGs98w01nFQUhbec1pNCkCsKVfpg", "AF6E3O0VE0X4D")
|
262 |
p = Products("AKIAII3SGRXBJDPCHSGQ", "B92xTbNBTYygbGs98w01nFQUhbec1pNCkCsKVfpg", "AF6E3O0VE0X4D")
|
| 236 |
#comp = p.get_competitive_pricing_for_sku('A21TJRUUN4KGV', ['FBA5791'])
|
263 |
#comp = p.get_competitive_pricing_for_sku('A21TJRUUN4KGV', ['FBA5791'])
|
| 237 |
our = p.get_my_pricing_for_sku('A21TJRUUN4KGV', ["FBG10570"])
|
264 |
our = p.get_product_attributes_for_sku('A21TJRUUN4KGV', ["12248"])
|
| 238 |
print our
|
265 |
print our
|
| 239 |
#cat = p.get_product_category_for_sku('A21TJRUUN4KGV', "FBA16803")
|
266 |
#cat = p.get_product_category_for_sku('A21TJRUUN4KGV', "FBA16803")
|
| 240 |
#print cat
|
267 |
#print cat
|
| 241 |
#print our
|
268 |
#print our
|
| 242 |
#print comp
|
269 |
#print comp
|