Subversion Repositories SmartDukaan

Rev

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

Rev 12482 Rev 12597
Line 4... Line 4...
4
import hashlib
4
import hashlib
5
import hmac
5
import hmac
6
import base64
6
import base64
7
from time import strftime, gmtime
7
from time import strftime, gmtime
8
from requests import request
8
from requests import request
9
from operator import itemgetter
-
 
10
 
9
 
11
 
10
 
12
class MWS(object):
11
class MWS(object):
13
    URI = "/"
12
    URI = "/"
14
    VERSION = "2009-01-01"
13
    VERSION = "2009-01-01"
Line 53... Line 52...
53
        spString = re.sub('<\?.*\?>','',response.text)
52
        spString = re.sub('<\?.*\?>','',response.text)
54
        spString = "<dom>" + spString + "</dom>"
53
        spString = "<dom>" + spString + "</dom>"
55
        dom = parseString(spString)
54
        dom = parseString(spString)
56
        skuOffers = dom.getElementsByTagName('GetLowestOfferListingsForSKUResult')
55
        skuOffers = dom.getElementsByTagName('GetLowestOfferListingsForSKUResult')
57
        offerMap = {}
56
        offerMap = {}
-
 
57
        otherInfo = {}
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'):
Line 88... Line 88...
88
                        temp['rating'] = '0'
88
                        temp['rating'] = '0'
89
                except:
89
                except:
90
                    pass
90
                    pass
91
                temp['notOurSku'] = True
91
                temp['notOurSku'] = True
92
                info.append(temp)
92
                info.append(temp)
93
                offerMap[sku]=info        
93
                offerMap[sku]=info
-
 
94
        for skuOffer in skuOffers:
-
 
95
            sku = skuOffer.attributes.items()[1][1]
-
 
96
            temp = {}
-
 
97
            temp['lowestMfnIgnored']=0.0
-
 
98
            temp['isLowestMfnIgnored']=False
-
 
99
            temp['lowestFba']=0.0
-
 
100
            temp['isLowestFba']=False
-
 
101
            temp['lowestMfn']=0.0
-
 
102
            temp['isLowestMfn']=False
-
 
103
            for offer in skuOffer.getElementsByTagName('LowestOfferListing'):
-
 
104
                try:
-
 
105
                    fulfillmentChannel = offer.getElementsByTagName('FulfillmentChannel')[0].firstChild.nodeValue
-
 
106
                    amount = offer.getElementsByTagName('Amount')[0].firstChild.nodeValue
-
 
107
                    try:
-
 
108
                        rating = (offer.getElementsByTagName('SellerPositiveFeedbackRating')[0].firstChild.nodeValue)
-
 
109
                        if rating == 'Just Launched':
-
 
110
                            rating = 0
-
 
111
                        else:
-
 
112
                            str_rating = rating.replace('-',' ').replace('%','')
-
 
113
                            a =  str_rating.split()
-
 
114
                            l = []
-
 
115
                            for x in a:
-
 
116
                                if x.isdigit():
-
 
117
                                    l.append(x)
-
 
118
                            rating = int(l[0])
-
 
119
                    except:
-
 
120
                        rating = 0
-
 
121
                    if fulfillmentChannel=='Merchant' and not temp['isLowestMfnIgnored'] and not temp['isLowestMfn'] and rating < 60:
-
 
122
                        temp['lowestMfnIgnored'] = float(amount)
-
 
123
                        temp['isLowestMfnIgnored']=True
-
 
124
                    elif fulfillmentChannel=='Merchant' and not temp['isLowestMfn'] and rating > 60:
-
 
125
                        temp['lowestMfn'] = float(amount)
-
 
126
                        temp['isLowestMfn']=True
-
 
127
                    elif fulfillmentChannel=='Amazon' and not temp['isLowestFba']:
-
 
128
                        temp['lowestFba'] = float(amount)
-
 
129
                        temp['isLowestFba']=True
-
 
130
                    else:
-
 
131
                        pass
-
 
132
                except:
-
 
133
                    pass
-
 
134
                otherInfo[sku]=temp
94
        return offerMap
135
        return offerMap, otherInfo
95
    
136
    
96
    def parse_my_pricing_response(self,response):
137
    def parse_my_pricing_response(self,response):
97
        spString = re.sub('<\?.*\?>','',response.text)
138
        spString = re.sub('<\?.*\?>','',response.text)
98
        spString = "<dom>" + spString + "</dom>"
139
        spString = "<dom>" + spString + "</dom>"
99
        dom = parseString(spString)
140
        dom = parseString(spString)
Line 162... Line 203...
162
            num+=1
203
            num+=1
163
        return self.make_request(data,'GetLowestOfferListingsForSKU')
204
        return self.make_request(data,'GetLowestOfferListingsForSKU')
164
    
205
    
165
def main():
206
def main():
166
    p = Products("AKIAII3SGRXBJDPCHSGQ", "B92xTbNBTYygbGs98w01nFQUhbec1pNCkCsKVfpg", "AF6E3O0VE0X4D")
207
    p = Products("AKIAII3SGRXBJDPCHSGQ", "B92xTbNBTYygbGs98w01nFQUhbec1pNCkCsKVfpg", "AF6E3O0VE0X4D")
167
    comp = p.get_competitive_pricing_for_sku('A21TJRUUN4KGV', ['FBA16293'])
208
    comp = p.get_competitive_pricing_for_sku('A21TJRUUN4KGV', ['FBA12248','FBA10969'])
168
    our = p.get_my_pricing_for_sku('A21TJRUUN4KGV', ['FBA3024'])
209
    #our = p.get_my_pricing_for_sku('A21TJRUUN4KGV', ['FBB12248'])
169
    print comp
210
    print comp[1]
170
    print our
211
    #print our
171
    #print our.get('promotion')
212
    #print our.get('promotion')
172
#    print comp.get('FBA12248')
213
#    print comp.get('FBA12248')
173
#    print our.get('FBA12248')
214
#    print our.get('FBA12248')
174
#    x = (our.get('FBA12248'))
215
#    x = (our.get('FBA12248'))
175
#    x['sellingPrice']=41089
216
#    x['sellingPrice']=41089
176
#    l = (comp.get('FBA12248'))
217
#    l = (comp.get('FBA12248'))
177
#    l.append((our.get('FBA12248')))
218
#    l.append((our.get('FBA12248')))
178
#    print sorted(l, key=itemgetter('promoPrice','notOurSku'))
219
#    print sorted(l, key=itemgetter('promoPrice','notOurSku'))
179
    
220
    
180
    
-
 
181
    
-
 
182
    
-
 
183
    
-
 
184
 
221
 
185
if __name__=='__main__':
222
if __name__=='__main__':
186
    main()
223
    main()
187
224