Subversion Repositories SmartDukaan

Rev

Rev 12434 | Rev 12437 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 12434 Rev 12436
Line 58... Line 58...
58
        for skuOffer in skuOffers:
58
        for skuOffer in skuOffers:
59
            status = skuOffer.attributes.items()[0][1]
59
            status = skuOffer.attributes.items()[0][1]
60
            sku = skuOffer.attributes.items()[1][1]
60
            sku = skuOffer.attributes.items()[1][1]
61
            info = []
61
            info = []
62
            for offer in skuOffer.getElementsByTagName('LowestOfferListing'):
62
            for offer in skuOffer.getElementsByTagName('LowestOfferListing'):
63
                if len(info)==3:
-
 
64
                    break
-
 
65
                temp = {}
63
                temp = {}
66
                amount = offer.getElementsByTagName('Amount')[0].firstChild.nodeValue
-
 
67
                temp['sellingPrice'] = amount
-
 
68
                temp['promoPrice'] = amount
-
 
69
                temp['fulfillmentChannel'] = offer.getElementsByTagName('FulfillmentChannel')[0].firstChild.nodeValue
-
 
70
                try:
64
                try:
-
 
65
                    if len(info)==3:
-
 
66
                        break
-
 
67
                    amount = offer.getElementsByTagName('Amount')[0].firstChild.nodeValue
-
 
68
                    temp['sellingPrice'] = amount
-
 
69
                    temp['promoPrice'] = amount
-
 
70
                    temp['fulfillmentChannel'] = offer.getElementsByTagName('FulfillmentChannel')[0].firstChild.nodeValue
-
 
71
                    try:
71
                    temp['shippingTime'] = (offer.getElementsByTagName('Max')[0].firstChild.nodeValue).replace('days','')
72
                        temp['shippingTime'] = (offer.getElementsByTagName('Max')[0].firstChild.nodeValue).replace('days','')
72
                except:
73
                    except:
73
                    temp['shippingTime'] = '0-0'
74
                        temp['shippingTime'] = '0-0'
74
                try:
75
                    try:
75
                    temp['rating'] = (offer.getElementsByTagName('SellerPositiveFeedbackRating')[0].firstChild.nodeValue)
76
                        temp['rating'] = (offer.getElementsByTagName('SellerPositiveFeedbackRating')[0].firstChild.nodeValue)
76
                    if temp['rating'] == 'Just Launched':
77
                        if temp['rating'] == 'Just Launched':
-
 
78
                            temp['rating'] = '0'
-
 
79
                        else:
-
 
80
                            str_rating = temp['rating'].replace('-',' ').replace('%','')
-
 
81
                            a =  str_rating.split()
-
 
82
                            l = []
-
 
83
                            for x in a:
-
 
84
                                if x.isdigit():
-
 
85
                                    l.append(x)
-
 
86
                            temp['rating'] = l[0]
-
 
87
                    except:
77
                        temp['rating'] = '0'
88
                        temp['rating'] = '0'
78
                    else:
-
 
79
                        str_rating = temp['rating'].replace('-',' ').replace('%','')
-
 
80
                        a =  str_rating.split()
-
 
81
                        l = []
-
 
82
                        for x in a:
-
 
83
                            if x.isdigit():
-
 
84
                                l.append(x)
-
 
85
                        temp['rating'] = l[0]
-
 
86
                except:
89
                except:
87
                    temp['rating'] = '0'
90
                    pass
88
                temp['notOurSku'] = True
91
                temp['notOurSku'] = True
89
                info.append(temp)
92
                info.append(temp)
90
            offerMap[sku]=info        
93
                offerMap[sku]=info        
91
        return offerMap
94
        return offerMap
92
    
95
    
93
    def parse_my_pricing_response(self,response):
96
    def parse_my_pricing_response(self,response):
-
 
97
        print response.text
94
        spString = re.sub('<\?.*\?>','',response.text)
98
        spString = re.sub('<\?.*\?>','',response.text)
95
        spString = "<dom>" + spString + "</dom>"
99
        spString = "<dom>" + spString + "</dom>"
96
        dom = parseString(spString)
100
        dom = parseString(spString)
97
        skuOffers = dom.getElementsByTagName('GetMyPriceForSKUResult')
101
        skuOffers = dom.getElementsByTagName('GetMyPriceForSKUResult')
98
        skuMap = {}
102
        skuMap = {}
Line 101... Line 105...
101
            sku = skuOffer.attributes.items()[1][1]
105
            sku = skuOffer.attributes.items()[1][1]
102
            asin = skuOffer.getElementsByTagName('ASIN')[0].firstChild.nodeValue
106
            asin = skuOffer.getElementsByTagName('ASIN')[0].firstChild.nodeValue
103
            print "fetching details of ",sku
107
            print "fetching details of ",sku
104
            for offer in skuOffer.getElementsByTagName('Offers'):
108
            for offer in skuOffer.getElementsByTagName('Offers'):
105
                temp = {}
109
                temp = {}
-
 
110
                try:
106
                promoPrice = offer.getElementsByTagName('LandedPrice')[0].getElementsByTagName('Amount')[0].firstChild.nodeValue
111
                    promoPrice = offer.getElementsByTagName('LandedPrice')[0].getElementsByTagName('Amount')[0].firstChild.nodeValue
107
                regularPrice = offer.getElementsByTagName('RegularPrice')[0].getElementsByTagName('Amount')[0].firstChild.nodeValue
112
                    regularPrice = offer.getElementsByTagName('RegularPrice')[0].getElementsByTagName('Amount')[0].firstChild.nodeValue
108
                temp['sellingPrice'] = regularPrice
113
                    temp['sellingPrice'] = regularPrice
109
                temp['promoPrice'] = promoPrice
114
                    temp['promoPrice'] = promoPrice
110
                if promoPrice == regularPrice:
115
                    if promoPrice == regularPrice:
111
                    temp['promotion'] = False
116
                        temp['promotion'] = False
112
                else:
117
                    else:
113
                    temp['promotion'] = True
118
                        temp['promotion'] = True
114
                temp['status'] = status
119
                    temp['status'] = status
115
                temp['asin'] = asin
120
                    temp['asin'] = asin
116
                temp['notOurSku'] = False
121
                    temp['notOurSku'] = False
117
                temp['fulfillmentChannel'] ='AMAZON'
122
                    temp['fulfillmentChannel'] ='AMAZON'
118
                temp['shippingTime'] =  '0-0'
123
                    temp['shippingTime'] =  '0-0'
119
                temp['rating'] = '0'
124
                    temp['rating'] = '0'
-
 
125
                except:
-
 
126
                    pass
120
            skuMap[sku]=temp     
127
                skuMap[sku]=temp     
121
        return skuMap    
128
        return skuMap    
122
        
129
        
123
        
130
        
124
    def calc_signature(self, method, request_description):
131
    def calc_signature(self, method, request_description):
125
        sig_data = method + '\n' + self.domain.replace('https://', '').lower() + '\n' + self.uri + '\n' + request_description
132
        sig_data = method + '\n' + self.domain.replace('https://', '').lower() + '\n' + self.uri + '\n' + request_description
Line 154... Line 161...
154
            num+=1
161
            num+=1
155
        return self.make_request(data,'GetLowestOfferListingsForSKU')
162
        return self.make_request(data,'GetLowestOfferListingsForSKU')
156
    
163
    
157
def main():
164
def main():
158
    p = Products("AKIAII3SGRXBJDPCHSGQ", "B92xTbNBTYygbGs98w01nFQUhbec1pNCkCsKVfpg", "AF6E3O0VE0X4D")
165
    p = Products("AKIAII3SGRXBJDPCHSGQ", "B92xTbNBTYygbGs98w01nFQUhbec1pNCkCsKVfpg", "AF6E3O0VE0X4D")
159
    comp = p.get_competitive_pricing_for_sku('A21TJRUUN4KGV', ['FBA12248','FBB12248'])
166
    comp = p.get_competitive_pricing_for_sku('A21TJRUUN4KGV', ['FBA10049'])
160
    our = p.get_my_pricing_for_sku('A21TJRUUN4KGV', ['FBA12248','FBB12248'])
167
    our = p.get_my_pricing_for_sku('A21TJRUUN4KGV', ['FBA10049'])
-
 
168
    print comp
-
 
169
    print our
161
    print comp.get('FBA12248')
170
#    print comp.get('FBA12248')
162
    print our.get('FBA12248')
171
#    print our.get('FBA12248')
163
    x = (our.get('FBA12248'))
172
#    x = (our.get('FBA12248'))
164
    x['sellingPrice']=41089
173
#    x['sellingPrice']=41089
165
    l = (comp.get('FBA12248'))
174
#    l = (comp.get('FBA12248'))
166
    l.append((our.get('FBA12248')))
175
#    l.append((our.get('FBA12248')))
167
    print sorted(l, key=itemgetter('promoPrice','notOurSku'))
176
#    print sorted(l, key=itemgetter('promoPrice','notOurSku'))
168
    
177
    
169
    
178
    
170
    
179
    
171
    
180
    
172
    
181