Subversion Repositories SmartDukaan

Rev

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

Rev 13582 Rev 13603
Line 12... Line 12...
12
import datetime
12
import datetime
13
import json
13
import json
14
import pymongo
14
import pymongo
15
import re
15
import re
16
import urllib
16
import urllib
-
 
17
import traceback
-
 
18
 
17
from pprint import pprint
19
from pprint import pprint
18
USERNAME='saholic1@gmail.com'
20
USERNAME='saholic1@gmail.com'
19
PASSWORD='spice@2020'
21
PASSWORD='spice@2020'
20
AFFILIATE_URL='http://affiliate.snapdeal.com'
22
AFFILIATE_URL='http://affiliate.snapdeal.com'
21
POST_URL='https://api-p03.hasoffers.com/v3/Affiliate_Report.json'
23
POST_URL='https://api-p03.hasoffers.com/v3/Affiliate_Report.json'
Line 118... Line 120...
118
                    elif "Offer Discount" in subTrString:
120
                    elif "Offer Discount" in subTrString:
119
                        offerDiscount =   re.findall(r'\d+', subTrString)[0]
121
                        offerDiscount =   re.findall(r'\d+', subTrString)[0]
120
                    elif "Delivery Charges" in subTrString:
122
                    elif "Delivery Charges" in subTrString:
121
                        deliveryCharges =   re.findall(r'\d+', subTrString)[0]
123
                        deliveryCharges =   re.findall(r'\d+', subTrString)[0]
122
                    elif "Subtotal" in subTrString:
124
                    elif "Subtotal" in subTrString:
-
 
125
                        if int(qty) > 0:
123
                        amountPaid =   str(int(re.findall(r'\d+', subTrString)[0])/int(qty))
126
                            amountPaid =   str(int(re.findall(r'\d+', subTrString)[0])/int(qty))
-
 
127
                        else:
-
 
128
                            amountPaid =   "0"
124
                        
129
                        
125
                divs = subOrderElement.findAll("div", {"class": "blk lrPad subordrs"})
130
                divs = subOrderElement.findAll("div", {"class": "blk lrPad subordrs"})
126
                if len(divs)<=0:
131
                if len(divs)<=0:
127
                    raise ParseException("subOrder", "Could not Parse suborders for Snapdeal")
132
                    raise ParseException("subOrder", "Could not Parse suborders for Snapdeal")
128
                
133
                
Line 165... Line 170...
165
            
170
            
166
            self._saveToOrder(todict(merchantOrder))
171
            self._saveToOrder(todict(merchantOrder))
167
            return True
172
            return True
168
        except:
173
        except:
169
            print "Error occurred"
174
            print "Error occurred"
-
 
175
            traceback.print_exc()
170
        
176
        
171
        return False
177
        return False
172
        #soup = BeautifulSoup(rawHtml,convertEntities=BeautifulSoup.HTML_ENTITIES)
178
        #soup = BeautifulSoup(rawHtml,convertEntities=BeautifulSoup.HTML_ENTITIES)
173
        #soup.find(name, attrs, recursive, text)
179
        #soup.find(name, attrs, recursive, text)
174
    
180
    
Line 260... Line 266...
260
        collection = self.db.merchantOrder
266
        collection = self.db.merchantOrder
261
        try:
267
        try:
262
            order = collection.insert(order)
268
            order = collection.insert(order)
263
            #merchantOder 
269
            #merchantOder 
264
        except Exception as e:
270
        except Exception as e:
265
            print todict(e)
271
            traceback.print_exc()
266
    
272
    
267
    def _getAllOffers(self, br, token):
273
    def _getAllOffers(self, br, token):
268
        allOffers = []
274
        allOffers = []
269
        nextPage = 1  
275
        nextPage = 1  
270
        while True:
276
        while True:
Line 317... Line 323...
317
    return urllib.urlencode(parameters)
323
    return urllib.urlencode(parameters)
318
 
324
 
319
def main():
325
def main():
320
    store = getStore(3)
326
    store = getStore(3)
321
    store.scrapeStoreOrders()
327
    store.scrapeStoreOrders()
322
    #store.scrapeAffiliate()
-
 
323
    #with open ("data.txt", "r") as myfile:
-
 
324
    #    data=myfile.read()
-
 
325
    #    myfile.close()
-
 
326
    
328
    
327
    #store.parseOrderRawHtml(12345, "subtagId", 122323,  "html", 'https://m.snapdeal.com/purchaseMobileComplete?code=1f4166d13ea799b65aa9dea68b3e9e70&order=4509499363')
329
    #store.parseOrderRawHtml(12345, "subtagId", 122323,  "html", 'https://m.snapdeal.com/purchaseMobileComplete?code=1f4166d13ea799b65aa9dea68b3e9e70&order=4509499363')
328
 
330
 
329
def ungzipResponse(r,b):
331
def ungzipResponse(r,b):
330
    headers = r.info()
332
    headers = r.info()