Subversion Repositories SmartDukaan

Rev

Rev 20347 | Rev 21135 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
15869 kshitij.so 1
import urllib2
2
from BeautifulSoup import BeautifulSoup
3
import pymongo
4
import re
20364 kshitij.so 5
from dtr.utils.utils import to_java_date, getNlcPoints, DEAL_PRIORITY, getCashBack
15869 kshitij.so 6
import optparse
7
from datetime import datetime
16183 kshitij.so 8
import time
15869 kshitij.so 9
import smtplib
10
from email.mime.text import MIMEText
11
from email.mime.multipart import MIMEMultipart
15895 kshitij.so 12
from dtr.utils import ShopCluesScraper
13
import traceback
16019 kshitij.so 14
from dtr.storage.MemCache import MemCache
16184 kshitij.so 15
import chardet
15869 kshitij.so 16
 
17
con = None
18
parser = optparse.OptionParser()
19
parser.add_option("-m", "--m", dest="mongoHost",
20
                      default="localhost",
21
                      type="string", help="The HOST where the mongo server is running",
22
                      metavar="mongo_host")
16102 kshitij.so 23
parser.add_option("-r", "--reset", dest="reset",
24
                   default="False", type="string",
25
                   help="Reset Ranks?")
15869 kshitij.so 26
 
27
(options, args) = parser.parse_args()
28
 
16869 kshitij.so 29
SOURCE_MAP = {'AMAZON':1,'FLIPKART':2,'SNAPDEAL':3,'SAHOLIC':4, 'SHOPCLUES.COM':5,'PAYTM.COM':6}
15869 kshitij.so 30
bestSellers = []
31
baseUrl = "http://m.shopclues.com/products/getProductList/mobiles:top-selling-mobiles-and-tablets.html/%s/page=%s"
15895 kshitij.so 32
headers = {
33
            'User-Agent':'Mozilla/5.0 (Linux; Android 4.3; Nexus 7 Build/JSS15Q) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.72 Safari/537.36',
34
            'Accept' : 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',      
35
            'Accept-Language' : 'en-US,en;q=0.8',                     
36
            'Accept-Charset' : 'ISO-8859-1,utf-8;q=0.7,*;q=0.3',
16019 kshitij.so 37
            'Connection':'keep-alive'
15895 kshitij.so 38
        }
15869 kshitij.so 39
now = datetime.now()
16019 kshitij.so 40
mc = MemCache(options.mongoHost)
16099 kshitij.so 41
sc = ShopCluesScraper.ShopCluesScraper(findThumbnail=True)
15869 kshitij.so 42
 
16095 kshitij.so 43
bundledProducts = []
44
exceptionList = []
15869 kshitij.so 45
 
16095 kshitij.so 46
 
15869 kshitij.so 47
class __ProductInfo:
48
 
49
    def __init__(self, identifier, rank, url, available_price, in_stock, codAvailable, source_product_name, thumbnail, coupon):
50
        self.identifier = identifier
51
        self.rank  = rank
52
        self.url = url
53
        self.available_price = available_price
54
        self.in_stock = in_stock
55
        self.codAvailable = codAvailable
56
        self.source_product_name = source_product_name
57
        self.thumbnail = thumbnail
16095 kshitij.so 58
        self.coupon = coupon
15869 kshitij.so 59
 
16095 kshitij.so 60
class __NewBundled:
61
    def __init__(self, newProduct, oldProduct):
62
        self.newProduct = newProduct
63
        self.oldProduct = oldProduct
64
 
15869 kshitij.so 65
def get_mongo_connection(host=options.mongoHost, port=27017):
66
    global con
67
    if con is None:
68
        print "Establishing connection %s host and port %d" %(host,port)
69
        try:
70
            con = pymongo.MongoClient(host, port)
71
        except Exception, e:
72
            print e
73
            return None
74
    return con
75
 
19189 kshitij.so 76
def getNetPriceForItem(itemId, source_id, category_id ,price):
77
    cash_back_type = 0
78
    cash_back = 0
79
    try:
80
        cashBack = getCashBack(itemId, source_id, category_id, mc, options.mongoHost)
81
        if not cashBack or cashBack.get('cash_back_status')!=1:
82
            cash_back_type = 0
83
            cash_back = 0 
84
 
85
        else:
86
            if cashBack['cash_back_type'] in (1,2):
87
 
88
                if cashBack.get('maxCashBack') is not None:
89
 
90
                    if cashBack.get('cash_back_type') ==1 and (float(cashBack.get('cash_back'))*price)/100 > cashBack.get('maxCashBack'):
91
                        cashBack['cash_back_type'] = 2
92
                        cashBack['cash_back'] = cashBack['maxCashBack']
93
                    elif cashBack.get('cash_back_type') ==2 and cashBack.get('cash_back') > cashBack.get('maxCashBack'):
94
                        cashBack['cash_back'] = cashBack['maxCashBack']
95
                    else:
96
                        pass
97
 
98
 
99
 
100
                cash_back_type = cashBack['cash_back_type']
101
                cash_back = float(cashBack['cash_back'])
102
    except Exception as cashBackEx:
103
        pass
104
 
105
    if cash_back_type ==1:
106
        return (price - float(cash_back)*price/100)
107
    elif cash_back_type ==2:
108
        return (price - cash_back)
109
    else:
110
        return price
111
 
112
 
15869 kshitij.so 113
def getSoupObject(url):
114
    print "Getting soup object for"
115
    print url
116
    global RETRY_COUNT
117
    RETRY_COUNT = 1 
118
    while RETRY_COUNT < 10:
119
        try:
120
            soup = None
16019 kshitij.so 121
            request = urllib2.Request(url, headers=headers)
15869 kshitij.so 122
            response = urllib2.urlopen(request)   
123
            response_data = response.read()
124
            response.close()
125
            try:
126
                page=response_data.decode("utf-8")
127
                soup = BeautifulSoup(page,convertEntities=BeautifulSoup.HTML_ENTITIES)
128
            except:
16019 kshitij.so 129
                print traceback.print_exc()
15869 kshitij.so 130
                soup = BeautifulSoup(response_data,convertEntities=BeautifulSoup.HTML_ENTITIES)
131
            if soup is None:
132
                raise
133
            return soup
134
        except Exception as e:
16019 kshitij.so 135
            traceback.print_exc()
15869 kshitij.so 136
            print "Retrying"
137
            RETRY_COUNT = RETRY_COUNT + 1
138
 
139
 
140
def scrapeBestSellers():
141
    global bestSellers
16095 kshitij.so 142
    global exceptionList
15869 kshitij.so 143
    bestSellers = []
144
    rank = 0
145
    page = 1
146
    while (True):
147
        url = (baseUrl)%(page,page-1)
148
        soup = getSoupObject(url)
149
        productDivs = soup.findAll('div',{'class':'pd-list-cont'})
150
        if productDivs is None or len(productDivs)==0:
151
            return
152
        for productDiv in productDivs:
153
            rank = rank + 1
154
            info_tag =  productDiv.find('a')
155
            link = info_tag['href']
156
            scin = info_tag['data-id'].strip()
157
            print link
158
            print scin
15895 kshitij.so 159
            productName = productDiv.find('div',{'class':'pdt-name'}).string
160
            try:
161
                productInfo = sc.read(link)
162
            except Exception as e:
163
                traceback.print_exc()
164
                continue
15869 kshitij.so 165
            product = list(get_mongo_connection().Catalog.MasterData.find({'source_id':5,'identifier':scin}))
166
            if len(product) > 0:
16505 kshitij.so 167
                if product[0].get('ignorePricing') ==1:
168
                    continue
16019 kshitij.so 169
                if productInfo['inStock'] ==1:
19189 kshitij.so 170
                    netPriceAfterCashBack = getNetPriceForItem(product[0]['_id'], SOURCE_MAP.get('SHOPCLUES.COM'), product[0]['category_id'], productInfo['price'])
16019 kshitij.so 171
                    get_mongo_connection().Catalog.MasterData.update({'_id':product[0]['_id']},{"$set":{'rank':rank, 'available_price':productInfo['price'], \
15895 kshitij.so 172
                                                                                                            'in_stock':productInfo['inStock'], 'codAvailable':productInfo['isCod'], \
16021 kshitij.so 173
                                                                                                            'coupon':productInfo['coupon'], 'updatedOn':to_java_date(datetime.now()),'priceUpdatedOn':to_java_date(datetime.now())}})
19189 kshitij.so 174
                    get_mongo_connection().Catalog.Deals.update({'_id':product[0]['_id']}, {'$set' : {'rank':rank,'available_price':productInfo['price'] , 'in_stock':productInfo['inStock'],'codAvailable':productInfo['isCod'],'netPriceAfterCashBack':netPriceAfterCashBack}})
16019 kshitij.so 175
                else:
19189 kshitij.so 176
                    netPriceAfterCashBack = getNetPriceForItem(product[0]['_id'], SOURCE_MAP.get('SHOPCLUES.COM'), product[0]['category_id'], product[0]['available_price'])
16019 kshitij.so 177
                    get_mongo_connection().Catalog.MasterData.update({'_id':product[0]['_id']}, {'$set' : {'updatedOn':to_java_date(datetime.now()),'in_stock':0,'priceUpdatedOn':to_java_date(datetime.now())}})
19189 kshitij.so 178
                    get_mongo_connection().Catalog.Deals.update({'_id':product[0]['_id']}, {'$set' : {'in_stock':0,'netPriceAfterCashBack':netPriceAfterCashBack}})
16019 kshitij.so 179
 
180
                try:
181
                    recomputeDeal(product[0])
182
                except:
183
                    print "Unable to compute deal for %s"%(product[0]['skuBundleId'])
184
 
15869 kshitij.so 185
            else:
186
                #Lets bundle product by finding similar url pattern
15895 kshitij.so 187
                uri = link.replace('http://m.shopclues.com','').replace(".html","")
188
                try:
189
                    int(uri[uri.rfind('-')+1:])
190
                    uri =  uri[:uri.rfind('-')]
191
                except:
192
                    pass
193
                product = list(get_mongo_connection().Catalog.MasterData.find({'source_id':5,'marketPlaceUrl':{'$regex': uri}}))
16099 kshitij.so 194
                toBundle = __ProductInfo(scin, rank, link, productInfo['price'], productInfo['inStock'],productInfo['isCod'], productName, productInfo['thumbnail'] ,productInfo['coupon'])
15869 kshitij.so 195
                if len(product) > 0:
15895 kshitij.so 196
                    bundleNewProduct(product[0], toBundle)
16028 kshitij.so 197
                    try:
198
                        recomputeDeal(product[0])
199
                    except:
200
                        print "Unable to compute deal for %s"%(product[0]['skuBundleId'])
15895 kshitij.so 201
                else:
202
                    exceptionList.append(toBundle)
15869 kshitij.so 203
        page = page+1
16019 kshitij.so 204
 
205
def populateNegativeDeals():
206
    negativeDeals = get_mongo_connection().Catalog.NegativeDeals.find().distinct('sku')
207
    mc.set("negative_deals", negativeDeals, 600)
208
 
16505 kshitij.so 209
#def recomputePoints(item, deal):
210
#    try:
211
#        if item.get('available_price') == deal['available_price']:
212
#            print "No need to compute points for %d , as price is still same" %(item['_id'])
213
#            raise
214
#        nlcPoints = getNlcPoints(item, deal['minNlc'], deal['maxNlc'], deal['available_price'])
215
#    except:
216
#        print traceback.print_exc()
217
#        nlcPoints = deal['nlcPoints']
218
#        
219
#    
220
#    bundleDealPoints = list(get_mongo_connection().Catalog.DealPoints.find({'skuBundleId':item['skuBundleId'],'startDate':{'$lte':to_java_date(datetime.now())},'endDate':{'$gte':to_java_date(datetime.now())}}))
221
#    if len(bundleDealPoints) > 0:
222
#        item['manualDealThresholdPrice'] = bundleDealPoints[0]['dealThresholdPrice']
223
#        dealPoints = bundleDealPoints[0]['dealPoints']
224
#    else:
225
#        dealPoints = 0
226
#        item['manualDealThresholdPrice'] = None    
227
#    
228
#    get_mongo_connection().Catalog.Deals.update({'_id':deal['_id']},{"$set":{'totalPoints':deal['totalPoints'] - deal['nlcPoints'] + nlcPoints - deal['dealPoints'] +dealPoints , 'nlcPoints': nlcPoints, 'dealPoints': dealPoints, 'manualDealThresholdPrice': item['manualDealThresholdPrice']}})
16019 kshitij.so 229
 
230
 
231
def recomputeDeal(item):
232
    """Lets recompute deal for this bundle"""
233
    print "Recomputing for bundleId %d" %(item.get('skuBundleId'))
234
    skuBundleId = item['skuBundleId']
19189 kshitij.so 235
 
236
    similarItems = list(get_mongo_connection().Catalog.Deals.find({'skuBundleId':skuBundleId}).sort([('netPriceAfterCashBack',pymongo.ASCENDING)]))
16019 kshitij.so 237
    bestPrice = float("inf")
238
    bestOne = None
239
    toUpdate = []
240
    prepaidBestPrice = float("inf")
241
    prepaidBestOne = None
242
    for similarItem in similarItems:
243
        if similarItem['codAvailable'] ==1:
244
            if mc.get("negative_deals") is None:
245
                populateNegativeDeals()
16181 kshitij.so 246
            if similarItem['in_stock'] == 0  or similarItem['_id'] in mc.get("negative_deals"):
16019 kshitij.so 247
                get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0, 'prepaidDeal':0 }})
248
                continue
249
            if similarItem['source_id'] == SOURCE_MAP.get('SHOPCLUES.COM') and similarItem['rank']==0:
250
                get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':0 }})
251
                continue
19189 kshitij.so 252
            if similarItem.get('netPriceAfterCashBack') < bestPrice:
16019 kshitij.so 253
                bestOne = similarItem
19189 kshitij.so 254
                bestPrice = similarItem.get('netPriceAfterCashBack')
20347 kshitij.so 255
            elif similarItem.get('netPriceAfterCashBack') == bestPrice:
256
 
257
                try:
258
                    if (DEAL_PRIORITY.index(int(similarItem['source_id'])) > DEAL_PRIORITY.index(int(bestOne['source_id']))):
259
                        continue
260
                except:
261
                    traceback.print_exc()
262
 
16019 kshitij.so 263
                bestOne = similarItem
19189 kshitij.so 264
                bestPrice = similarItem.get('netPriceAfterCashBack')
16019 kshitij.so 265
            else:
266
                pass
267
        else:
268
            if mc.get("negative_deals") is None:
269
                populateNegativeDeals()
16181 kshitij.so 270
            if similarItem['in_stock'] == 0  or similarItem['_id'] in mc.get("negative_deals"):
16019 kshitij.so 271
                get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0, 'prepaidDeal':0 }})
272
                continue
273
            if similarItem['source_id'] == SOURCE_MAP.get('SHOPCLUES.COM') and similarItem['rank']==0:
274
                get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':0 }})
275
                continue
19189 kshitij.so 276
            if similarItem.get('netPriceAfterCashBack') < prepaidBestPrice:
16019 kshitij.so 277
                prepaidBestOne = similarItem
19189 kshitij.so 278
                prepaidBestPrice = similarItem.get('netPriceAfterCashBack')
20347 kshitij.so 279
            elif similarItem.get('netPriceAfterCashBack') == prepaidBestPrice:
280
 
281
                try:
20364 kshitij.so 282
                    if (DEAL_PRIORITY.index(int(similarItem['source_id'])) > DEAL_PRIORITY.index(int(prepaidBestOne['source_id']))):
20347 kshitij.so 283
                        continue
284
                except:
285
                    traceback.print_exc()
286
 
16019 kshitij.so 287
                prepaidBestOne = similarItem
19189 kshitij.so 288
                prepaidBestPrice = similarItem.get('netPriceAfterCashBack')
16019 kshitij.so 289
            else:
290
                pass
16026 kshitij.so 291
    if bestOne is not None or prepaidBestOne is not None:
16019 kshitij.so 292
        for similarItem in similarItems:
293
            toUpdate.append(similarItem['_id'])
16026 kshitij.so 294
        if bestOne is not None:
295
            toUpdate.remove(bestOne['_id'])
296
            get_mongo_connection().Catalog.Deals.update({ '_id' : bestOne['_id'] }, {'$set':{'showDeal':1,'prepaidDeal':0 }})
297
        if prepaidBestOne is not None:
16076 kshitij.so 298
            if bestOne is not None:
19189 kshitij.so 299
                if prepaidBestOne.get('netPriceAfterCashBack') < bestOne.get('netPriceAfterCashBack'): 
16076 kshitij.so 300
                    toUpdate.remove(prepaidBestOne['_id'])
301
                    get_mongo_connection().Catalog.Deals.update({ '_id' : prepaidBestOne['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':1 }})
302
            else:
303
                toUpdate.remove(prepaidBestOne['_id'])
304
                get_mongo_connection().Catalog.Deals.update({ '_id' : prepaidBestOne['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':1 }})
16019 kshitij.so 305
    if len(toUpdate) > 0:
306
        get_mongo_connection().Catalog.Deals.update({ '_id' : { "$in": toUpdate } }, {'$set':{'showDeal':0,'prepaidDeal':0 }},upsert=False, multi=True)
307
 
19189 kshitij.so 308
 
309
 
15869 kshitij.so 310
 
311
def bundleNewProduct(existingProduct, toBundle):
16095 kshitij.so 312
    global bundledProducts
313
    global exceptionList
15895 kshitij.so 314
    print "Adding new product"
315
    try:
316
        max_id = list(get_mongo_connection().Catalog.MasterData.find().sort([('_id',pymongo.DESCENDING)]).limit(1))
317
        existingProduct['_id'] = max_id[0]['_id'] + 1
318
        existingProduct['addedOn'] = to_java_date(datetime.now())
319
        existingProduct['available_price'] = toBundle.available_price
320
        existingProduct['updatedOn'] = to_java_date(datetime.now())
321
        existingProduct['codAvailable'] = toBundle.codAvailable
16095 kshitij.so 322
        existingProduct['coupon'] = str(toBundle.coupon)
323
        existingProduct['identifier'] = str(toBundle.identifier)
15895 kshitij.so 324
        existingProduct['in_stock'] = toBundle.in_stock
325
        existingProduct['marketPlaceUrl'] = toBundle.url
326
        existingProduct['rank'] = toBundle.rank
327
        existingProduct['source_product_name'] = toBundle.source_product_name
328
        existingProduct['url'] = toBundle.url
17747 kshitij.so 329
        existingProduct['showVideo'] = 0
330
        existingProduct['shippingCost'] = 0
331
        existingProduct['quantity'] = 1
332
        existingProduct['videoLink'] = ""
19189 kshitij.so 333
        existingProduct['showNetPrice'] = 0
15895 kshitij.so 334
        get_mongo_connection().Catalog.MasterData.insert(existingProduct)
16095 kshitij.so 335
        newBundled = __NewBundled(toBundle, existingProduct)
336
        bundledProducts.append(newBundled)
15895 kshitij.so 337
        return {1:'Data added successfully.'}
338
    except Exception as e:
339
        print e
16095 kshitij.so 340
        exceptionList.append(toBundle)
15895 kshitij.so 341
        return {0:'Unable to add data.'}
15869 kshitij.so 342
 
16095 kshitij.so 343
def sendMail():
344
    message="""<html>
345
            <body>
346
            <h3>ShopClues Best Sellers Auto Bundled</h3>
347
            <table border="1" style="width:100%;">
348
            <thead>
349
            <tr>
350
            <th>Item Id</th>
351
            <th>Identifier</th>
352
            <th>Rank</th>
353
            <th>Product Name</th>
354
            <th>Bundle Id</th>
355
            <th>Bundled with Brand</th>
356
            <th>Bundled with Product Name</th>
357
            <th>Available_price</th>
358
            <th>In Stock</th>
359
            <th>Coupon</th>
360
            <th>COD Available</th>
361
            </tr></thead>
362
            <tbody>"""
363
    for bundledProduct in bundledProducts:
364
        newProduct = bundledProduct.newProduct
365
        oldProduct = bundledProduct.oldProduct
366
        message+="""<tr>
367
        <td style="text-align:center">"""+str(oldProduct.get('_id'))+"""</td>
368
        <td style="text-align:center">"""+oldProduct.get('identifier')+"""</td>
369
        <td style="text-align:center">"""+str(oldProduct.get('rank'))+"""</td>
370
        <td style="text-align:center">"""+(oldProduct.get('source_product_name'))+"""</td>
371
        <td style="text-align:center">"""+str(oldProduct.get('skuBundleId'))+"""</td>
372
        <td style="text-align:center">"""+(oldProduct.get('brand'))+"""</td>
373
        <td style="text-align:center">"""+(oldProduct.get('product_name'))+"""</td>
374
        <td style="text-align:center">"""+str(oldProduct.get('available_price'))+"""</td>
375
        <td style="text-align:center">"""+str(oldProduct.get('in_stock'))+"""</td>
376
        <td style="text-align:center">"""+str(oldProduct.get('coupon'))+"""</td>
377
        <td style="text-align:center">"""+str(oldProduct.get('codAvailable'))+"""</td>
378
        </tr>"""
379
    message+="""</tbody></table><h3>Items not bundled</h3><table border="1" style="width:100%;">
380
    <tr>
381
    <th>Identifier</th>
382
    <th>Rank</th>
383
    <th>Product Name</th>
384
    <th>Url</th>
385
    <th>Available Price</th>
386
    <th>In Stock</th>
387
    <th>COD Available</th>
388
    <th>Coupon</th>
16099 kshitij.so 389
    <th>Thumbnail</th>
16095 kshitij.so 390
    </tr></thead>
391
    <tbody>"""
392
    for exceptionItem in exceptionList:
393
        message+="""<tr>
394
        <td style="text-align:center">"""+str(exceptionItem.identifier)+"""</td>
395
        <td style="text-align:center">"""+str(exceptionItem.rank)+"""</td>
396
        <td style="text-align:center">"""+(exceptionItem.source_product_name)+"""</td>
397
        <td style="text-align:center">"""+(exceptionItem.url)+"""</td>
398
        <td style="text-align:center">"""+str(exceptionItem.available_price)+"""</td>
399
        <td style="text-align:center">"""+str(exceptionItem.in_stock)+"""</td>
400
        <td style="text-align:center">"""+str(exceptionItem.codAvailable)+"""</td>
401
        <td style="text-align:center">"""+str(exceptionItem.coupon)+"""</td>
16102 kshitij.so 402
        <td style="text-align:left">"""+(exceptionItem.thumbnail)+"""</td>
16095 kshitij.so 403
        </tr>"""
404
    message+="""</tbody></table></body></html>"""
405
    print message
16184 kshitij.so 406
    encoding = chardet.detect(message)
407
    try:
408
        message = message.decode(encoding.get('encoding'))
409
    except:
410
        pass
16182 kshitij.so 411
    #recipients = ['kshitij.sood@saholic.com']
20172 aman.kumar 412
    recipients = ['rajneesh.arora@saholic.com','kshitij.sood@saholic.com','chaitnaya.vats@saholic.com','ritesh.chauhan@saholic.com','khushal.bhatia@saholic.com']
16095 kshitij.so 413
    msg = MIMEMultipart()
414
    msg['Subject'] = "Shopclues Best Sellers" + ' - ' + str(datetime.now())
415
    msg['From'] = ""
416
    msg['To'] = ",".join(recipients)
417
    msg.preamble = "Shopclues Best Sellers" + ' - ' + str(datetime.now())
418
    html_msg = MIMEText(message, 'html')
419
    msg.attach(html_msg)
420
 
421
    smtpServer = smtplib.SMTP('localhost')
422
    smtpServer.set_debuglevel(1)
423
    sender = 'dtr@shop2020.in'
424
    try:
425
        smtpServer.sendmail(sender, recipients, msg.as_string())
426
        print "Successfully sent email"
427
    except:
16101 kshitij.so 428
        traceback.print_exc()
16095 kshitij.so 429
        print "Error: unable to send email."
430
 
16183 kshitij.so 431
def resetRanks():
16103 kshitij.so 432
    get_mongo_connection().Catalog.MasterData.update({'rank':{'$gt':0},'source_id':5},{'$set' : {'rank':0,'updatedOn':to_java_date(now)}}, multi=True)
15895 kshitij.so 433
 
15869 kshitij.so 434
def main():
16103 kshitij.so 435
    if options.reset == 'True':
436
        resetRanks()
15869 kshitij.so 437
    scrapeBestSellers()
16102 kshitij.so 438
    if len(bundledProducts)>0 or len(exceptionList) > 0:
439
        sendMail()
16190 kshitij.so 440
    else:
441
        "print nothing to send"
15869 kshitij.so 442
 
443
if __name__=='__main__':
444
    main()