| Line 32... |
Line 32... |
| 32 |
'SignatureMethod': 'HmacSHA256',
|
32 |
'SignatureMethod': 'HmacSHA256',
|
| 33 |
'Action': action
|
33 |
'Action': action
|
| 34 |
}
|
34 |
}
|
| 35 |
if action=='GetLowestOfferListingsForSKU':
|
35 |
if action=='GetLowestOfferListingsForSKU':
|
| 36 |
params['ExcludeMe']='true'
|
36 |
params['ExcludeMe']='true'
|
| - |
|
37 |
if action =='GetLowestOfferListingsForASIN':
|
| - |
|
38 |
params['ItemCondition'] = 'New'
|
| 37 |
params.update(extra_data)
|
39 |
params.update(extra_data)
|
| 38 |
request_description = '&'.join(['%s=%s' % (k, urllib.quote(params[k], safe='-_.~').encode('utf-8')) for k in sorted(params)])
|
40 |
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)
|
41 |
signature = self.calc_signature(method, request_description)
|
| 40 |
url = '%s%s?%s&Signature=%s' % (self.domain, self.uri, request_description, urllib.quote(signature))
|
42 |
url = '%s%s?%s&Signature=%s' % (self.domain, self.uri, request_description, urllib.quote(signature))
|
| 41 |
print url
|
43 |
print url
|
| Line 48... |
Line 50... |
| 48 |
return self.parse_my_pricing_response(response)
|
50 |
return self.parse_my_pricing_response(response)
|
| 49 |
elif action=='GetProductCategoriesForSKU':
|
51 |
elif action=='GetProductCategoriesForSKU':
|
| 50 |
return self.parse_product_category_for_sku(response)
|
52 |
return self.parse_product_category_for_sku(response)
|
| 51 |
elif action=='GetMatchingProductForId':
|
53 |
elif action=='GetMatchingProductForId':
|
| 52 |
return self.parse_product_attributes(response)
|
54 |
return self.parse_product_attributes(response)
|
| - |
|
55 |
elif action=='GetLowestOfferListingsForASIN':
|
| - |
|
56 |
return self.parse_lowest_pricing_asins(response)
|
| 53 |
else:
|
57 |
else:
|
| 54 |
raise
|
58 |
raise
|
| 55 |
|
59 |
|
| 56 |
def parse_product_category_for_sku(self,response):
|
60 |
def parse_product_category_for_sku(self,response):
|
| - |
|
61 |
print response.text
|
| 57 |
browseNodes = []
|
62 |
browseNodes = []
|
| 58 |
#node = ""
|
63 |
#node = ""
|
| 59 |
spString = re.sub('<\?.*\?>','',response.text)
|
64 |
spString = re.sub('<\?.*\?>','',response.text)
|
| 60 |
spString = "<dom>" + spString + "</dom>"
|
65 |
spString = "<dom>" + spString + "</dom>"
|
| 61 |
dom = parseString(spString)
|
66 |
dom = parseString(spString)
|
| Line 78... |
Line 83... |
| 78 |
height = dimension.getElementsByTagName("ns2:Height")[0].firstChild.nodeValue #Inch
|
83 |
height = dimension.getElementsByTagName("ns2:Height")[0].firstChild.nodeValue #Inch
|
| 79 |
length = dimension.getElementsByTagName("ns2:Length")[0].firstChild.nodeValue #Inch
|
84 |
length = dimension.getElementsByTagName("ns2:Length")[0].firstChild.nodeValue #Inch
|
| 80 |
width = dimension.getElementsByTagName("ns2:Width")[0].firstChild.nodeValue #Inch
|
85 |
width = dimension.getElementsByTagName("ns2:Width")[0].firstChild.nodeValue #Inch
|
| 81 |
weight = dimension.getElementsByTagName("ns2:Weight")[0].firstChild.nodeValue #Pounds
|
86 |
weight = dimension.getElementsByTagName("ns2:Weight")[0].firstChild.nodeValue #Pounds
|
| 82 |
return {'sku':sku,'length':length,'width':width,'height':height,'weight':weight}
|
87 |
return {'sku':sku,'length':length,'width':width,'height':height,'weight':weight}
|
| 83 |
|
- |
|
| 84 |
|
88 |
|
| - |
|
89 |
def parse_lowest_pricing_asins(self,response):
|
| - |
|
90 |
#GetLowestOfferListingsForASINResult
|
| - |
|
91 |
spString = re.sub('<\?.*\?>','',response.text)
|
| - |
|
92 |
spString = "<dom>" + spString + "</dom>"
|
| - |
|
93 |
dom = parseString(spString)
|
| - |
|
94 |
asinOffers = dom.getElementsByTagName('GetLowestOfferListingsForASINResult')
|
| - |
|
95 |
asinMap = {}
|
| - |
|
96 |
for asinOffer in asinOffers:
|
| - |
|
97 |
asin = asinOffer.attributes.items()[1][1]
|
| - |
|
98 |
asinMap[asin] = 0.0
|
| - |
|
99 |
for offer in asinOffer.getElementsByTagName('LowestOfferListing'):
|
| - |
|
100 |
price = offer.getElementsByTagName('Amount')[0].firstChild.nodeValue
|
| - |
|
101 |
asinMap[asin] = price
|
| - |
|
102 |
break
|
| - |
|
103 |
return asinMap
|
| - |
|
104 |
|
| - |
|
105 |
|
| 85 |
def parse_competitor_pricing_response(self,response):
|
106 |
def parse_competitor_pricing_response(self,response):
|
| 86 |
spString = re.sub('<\?.*\?>','',response.text)
|
107 |
spString = re.sub('<\?.*\?>','',response.text)
|
| 87 |
spString = "<dom>" + spString + "</dom>"
|
108 |
spString = "<dom>" + spString + "</dom>"
|
| 88 |
dom = parseString(spString)
|
109 |
dom = parseString(spString)
|
| 89 |
skuOffers = dom.getElementsByTagName('GetLowestOfferListingsForSKUResult')
|
110 |
skuOffers = dom.getElementsByTagName('GetLowestOfferListingsForSKUResult')
|
| Line 251... |
Line 272... |
| 251 |
data = dict(SellerId=self.merchant_id, MarketplaceId=marketplaceid)
|
272 |
data = dict(SellerId=self.merchant_id, MarketplaceId=marketplaceid)
|
| 252 |
num=0
|
273 |
num=0
|
| 253 |
for sku in skus:
|
274 |
for sku in skus:
|
| 254 |
data['IdList.Id.%d' % (num + 1)] = sku
|
275 |
data['IdList.Id.%d' % (num + 1)] = sku
|
| 255 |
num+=1
|
276 |
num+=1
|
| 256 |
data['IdType'] = 'SellerSKU'
|
277 |
data['IdType'] = 'ASIN'
|
| 257 |
print data
|
278 |
print data
|
| 258 |
return self.make_request(data,'GetMatchingProductForId')
|
279 |
return self.make_request(data,'GetMatchingProductForId')
|
| 259 |
|
280 |
|
| - |
|
281 |
def get_competitive_pricing_for_asin(self, marketplaceid, asins):
|
| - |
|
282 |
data = dict(SellerId=self.merchant_id, MarketplaceId=marketplaceid)
|
| - |
|
283 |
num=0
|
| - |
|
284 |
for asin in asins:
|
| - |
|
285 |
data['ASINList.ASIN.%d' % (num + 1)] = asin
|
| - |
|
286 |
num+=1
|
| - |
|
287 |
return self.make_request(data,'GetLowestOfferListingsForASIN')
|
| - |
|
288 |
|
| - |
|
289 |
|
| 260 |
|
290 |
|
| 261 |
def main():
|
291 |
def main():
|
| 262 |
p = Products("AKIAII3SGRXBJDPCHSGQ", "B92xTbNBTYygbGs98w01nFQUhbec1pNCkCsKVfpg", "AF6E3O0VE0X4D")
|
292 |
p = Products("AKIAII3SGRXBJDPCHSGQ", "B92xTbNBTYygbGs98w01nFQUhbec1pNCkCsKVfpg", "AF6E3O0VE0X4D")
|
| 263 |
#comp = p.get_competitive_pricing_for_sku('A21TJRUUN4KGV', ['FBA5791'])
|
- |
|
| 264 |
our = p.get_product_attributes_for_sku('A21TJRUUN4KGV', ["12248"])
|
- |
|
| 265 |
print our
|
- |
|
| 266 |
#cat = p.get_product_category_for_sku('A21TJRUUN4KGV', "FBA16803")
|
- |
|
| 267 |
#print cat
|
- |
|
| 268 |
#print our
|
- |
|
| 269 |
#print comp
|
- |
|
| 270 |
# for k, v in our.iteritems():
|
- |
|
| 271 |
# print k,
|
- |
|
| 272 |
# print '\t',
|
- |
|
| 273 |
# print v['sellingPrice'],
|
- |
|
| 274 |
# print v['promoPrice'],
|
- |
|
| 275 |
# print v['asin']
|
- |
|
| 276 |
#print our.get('promotion')
|
- |
|
| 277 |
# print comp.get('FBA12248')
|
- |
|
| 278 |
# print our.get('FBA12248')
|
- |
|
| 279 |
# x = (our.get('FBA12248'))
|
- |
|
| 280 |
# x['sellingPrice']=41089
|
- |
|
| 281 |
# l = (comp.get('FBA12248'))
|
- |
|
| 282 |
# l.append((our.get('FBA12248')))
|
- |
|
| 283 |
# print sorted(l, key=itemgetter('promoPrice','notOurSku'))
|
293 |
print p.get_competitive_pricing_for_asin("A21TJRUUN4KGV", ["B0168L23VS", "B017LRFNBK", "B01B7LZS8O", "B01CTWJIX6", "B01BHWRDVS", "B015J6B94U", "B015U5MBVA", "B01ALFQM82", "B0188ZHVZU", "B01CZPKANO", "B018K47ZK0", "B01BIYAXGW", "B01AUXJYMQ", "B01AI57N6K", "B01DY912SM", "B0119F11PW", "B0191UMYV2", "B017G6BPZY", "B01DDE8U88", "B01BGMMJZO"])
|
| 284 |
|
- |
|
| 285 |
|
294 |
|
| 286 |
if __name__=='__main__':
|
295 |
if __name__=='__main__':
|
| 287 |
main()
|
296 |
main()
|