Subversion Repositories SmartDukaan

Rev

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

Rev 14412 Rev 14460
Line 86... Line 86...
86
                        closedStatus = False
86
                        closedStatus = False
87
                        merchantSubOrderId = merchantSubOrderId + str(i)
87
                        merchantSubOrderId = merchantSubOrderId + str(i)
88
                        subOrder =  self._isSubOrderActive(order, merchantSubOrderId)
88
                        subOrder =  self._isSubOrderActive(order, merchantSubOrderId)
89
                        if subOrder is None:
89
                        if subOrder is None:
90
                            break
90
                            break
-
 
91
                        elif subOrder['closed']:
-
 
92
                            break
91
                        findMap = {"orderId": order['orderId'], "subOrders.merchantSubOrderId": merchantSubOrderId}
93
                        findMap = {"orderId": order['orderId'], "subOrders.merchantSubOrderId": merchantSubOrderId}
92
                        divs = orderItem.findAll('div', recursive=False)
94
                        divs = orderItem.findAll('div', recursive=False)
93
                        orderTracking = divs[2]
95
                        orderTracking = divs[2]
94
                        orderTrackingDetDiv = divs[3].find('div',{'class':'c-tabs-content m-top active'})
96
                        orderTrackingDetDiv = divs[3].find('div',{'class':'c-tabs-content m-top active'})
95
                        orderTrackingDet = orderTrackingDetDiv.find('div',{'class':re.compile('tracking-remark')}).text
97
                        orderTrackingDet = orderTrackingDetDiv.find('div',{'class':re.compile('tracking-remark')}).text
Line 137... Line 139...
137
            except:
139
            except:
138
                tprint("Could not update " + str(order['orderId']))
140
                tprint("Could not update " + str(order['orderId']))
139
                traceback.print_exc()
141
                traceback.print_exc()
140
    def scrapeAffiliate(self, startDate=None, endDate=None):
142
    def scrapeAffiliate(self, startDate=None, endDate=None):
141
        #get all yesterday's affiliate in pending or cancelled state and update to system
143
        #get all yesterday's affiliate in pending or cancelled state and update to system
142
        if datetime.now().hour == 1:
144
        if datetime.now().hour == 6:
-
 
145
            offers = []
143
            br = getBrowserObject()
146
            br = getBrowserObject()
144
            br.open(AFFILIATE_URL)
147
            br.open(AFFILIATE_URL)
145
            response = br.response()  # copy
148
            response = br.response()  # copy
146
            token =  re.findall('window.__FK = "(.*?)"', ungzipResponse(response), re.IGNORECASE)[0]
149
            token =  re.findall('window.__FK = "(.*?)"', ungzipResponse(response), re.IGNORECASE)[0]
147
            data = {'__FK':token,
150
            data = {'__FK':token,
148
                    'email':'saholic1@gmail.com',
151
                    'email':'saholic1@gmail.com',
149
                    'password':'e8aacf6fc1e3998186a4a8e56e428f66'
152
                    'password':'e8aacf6fc1e3998186a4a8e56e428f66'
150
            }
153
            }
151
            br.open(AFFILIATE_LOGIN_URL, urllib.urlencode(data))
154
            br.open(AFFILIATE_LOGIN_URL, urllib.urlencode(data))
152
            offers = []
-
 
153
            for delta in 1,2,3,4,5, 6,7:
155
            for delta in range(1,45):
154
                yester5date = date.today() - timedelta(delta)
156
                yester5date = date.today() - timedelta(delta)
155
                syester5date = yester5date.strftime('%Y-%m-%d')
157
                syester5date = yester5date.strftime('%Y-%m-%d')
156
                for status in [AFF_STATUS_PENDING, AFF_STATUS_CANCELLED, AFF_STATUS_DISAPPROVED]:
158
                for status in [AFF_STATUS_PENDING, AFF_STATUS_CANCELLED, AFF_STATUS_DISAPPROVED]:
-
 
159
                    try:
157
                    br.open(AFF_REPORT_URL % (status, syester5date, syester5date))
160
                        br.open(AFF_REPORT_URL % (status, syester5date, syester5date))
-
 
161
                    except:
-
 
162
                        tprint("Could not fetch data for Status %s and date %s"%(status, syester5date))
158
                    page = ungzipResponse(br.response())
163
                    page = ungzipResponse(br.response())
159
                    soup = BeautifulSoup(page,convertEntities=BeautifulSoup.HTML_ENTITIES)
164
                    soup = BeautifulSoup(page,convertEntities=BeautifulSoup.HTML_ENTITIES)
160
                    soup.table
165
                    soup.table
161
                    try:
166
                    try:
162
                        tableElement = soup.findAll('table', {'class':'report-table fixtable'})[1]
167
                        tableElement = soup.findAll('table', {'class':'report-table fixtable'})[1]
Line 170... Line 175...
170
                        quantity =int(tdElements[3].text)
175
                        quantity =int(tdElements[3].text)
171
                        price = int(float(tdElements[2].text.strip().replace(",","")))
176
                        price = int(float(tdElements[2].text.strip().replace(",","")))
172
                        payOut = int(float(tdElements[6].text.strip().replace(",","")))
177
                        payOut = int(float(tdElements[6].text.strip().replace(",","")))
173
                        saleAmount = int(float(tdElements[4].text.strip().replace(",","")))
178
                        saleAmount = int(float(tdElements[4].text.strip().replace(",","")))
174
                        subTagId = tdElements[7].text.strip()
179
                        subTagId = tdElements[7].text.strip()
175
                        updateMap={}
180
                        category = tdElements[1].text.strip()
176
                        affiliateInfo = FlipkartAffiliateInfo(subTagId, syester5date, productCode, price, quantity, saleAmount, payOut, status) 
181
                        affiliateInfo = FlipkartAffiliateInfo(subTagId, syester5date, productCode, price, quantity, saleAmount, payOut, status, category) 
177
                        offers.append(todict(affiliateInfo))
-
 
178
                        #updateMap['subOrders.$.unitPrice'] = price
182
                        #updateMap['subOrders.$.unitPrice'] = price
179
                        #updateMap['subOrders.$.cashBackAmount'], updateMap['subOrders.$.cashBacPercentage'] = self.getCashbackAmount(productCode, price)
183
                        #updateMap['subOrders.$.cashBackAmount'], updateMap['subOrders.$.cashBacPercentage'] = self.getCashbackAmount(productCode, price)
180
                        self._updateOrdersPayBackStatus({'subTagId':subTagId, 'subOrders.productCode':productCode}, updateMap)
-
 
181
            print offers
184
                        offers.append(affiliateInfo)
182
            self._saveToAffiliate(offers)
185
            self._saveToAffiliate(offers)
183
        
-
 
184
    
186
    
185
    def _saveToAffiliate(self, offers):
187
    def _saveToAffiliate(self, offers):
186
        if offers is None or len(offers)==0:
-
 
187
            print "no affiliate have been pushed"
-
 
188
            return
-
 
189
        collection = self.db.flipkartOrderAffiliateInfo
188
        collection = self.db.flipkartOrderAffiliateInfo
-
 
189
        mcollection = self.db.merchantOrder
190
        try:
190
        for offer in offers:
-
 
191
            result1 = collection.update({"subTagId":offer.subTagId, "price":offer.price, "quantity":offer.quantity, "saleDate":offer.saleDate, "productCode":offer.productCode},{"$set":todict(offer)}, upsert=True)
191
            collection.insert(offers,continue_on_error=True)
192
            if result1.get("upserted") is not None:
-
 
193
                result2 = mcollection.update({"subTagId":offer.subTagId, "storeId":self.store_id, "subOrders.missingAff":True, "subOrders.productCode":offer.productCode}, {"$set":{"subOrders.$.missingAff":False}}, multi=True)
192
        except pymongo.errors.DuplicateKeyError as e:
194
                if result2.get("updatedExisting") is True:
-
 
195
                    mcollection.update({"_id":result1.get("upserted")}, {"missingOrders":False})
193
            print e.details
196
                
194
            
197
            
195
            
198
            
196
    def parseOrderRawHtml(self, orderId, subTagId, userId, rawHtml, orderSuccessUrl):
199
    def parseOrderRawHtml(self, orderId, subTagId, userId, rawHtml, orderSuccessUrl):
197
        resp= {}
200
        resp= {}
198
        try:
201
        try: