Subversion Repositories SmartDukaan

Rev

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

Rev 19645 Rev 19647
Line 71... Line 71...
71
            rank = rank + 1
71
            rank = rank + 1
72
 
72
 
73
def commitBestSellers(category):
73
def commitBestSellers(category):
74
    global exceptionList
74
    global exceptionList
75
    for x in bestSellers:
75
    for x in bestSellers:
76
        col = get_mongo_connection().Catalog.MasterData.find({'identifier':x.identifier.strip(),'category_id':category})
76
        col = get_mongo_connection(host=options.mongoHost).Catalog.MasterData.find({'identifier':x.identifier.strip(),'category_id':category})
77
        if len(list(col)) == 0:
77
        if len(list(col)) == 0:
78
            x.category = category
78
            x.category = category
79
            exceptionList.append(x)
79
            exceptionList.append(x)
80
        else:
80
        else:
81
            get_mongo_connection().Catalog.MasterData.update({'identifier':x.identifier.strip(),'category_id':category}, {'$set' : {'rank':x.rank,'updatedOn':to_java_date(now)}}, multi=True)
81
            get_mongo_connection(host=options.mongoHost).Catalog.MasterData.update({'identifier':x.identifier.strip(),'category_id':category}, {'$set' : {'rank':x.rank,'updatedOn':to_java_date(now)}}, multi=True)
82
 
82
 
83
def resetRanks(category):
83
def resetRanks(category):
84
    get_mongo_connection().Catalog.MasterData.update({'category_id':category}, {'$set' : {'rank':0,'updatedOn':to_java_date(now)}}, multi=True)
84
    get_mongo_connection(host=options.mongoHost).Catalog.MasterData.update({'category_id':category}, {'$set' : {'rank':0,'updatedOn':to_java_date(now)}}, multi=True)
85
 
85
 
86
def sendEmail():
86
def sendEmail():
87
    message="""<html>
87
    message="""<html>
88
            <body>
88
            <body>
89
            <h3>Flipkart Best Sellers not in master</h3>
89
            <h3>Flipkart Best Sellers not in master</h3>
Line 123... Line 123...
123
        print "Successfully sent email"
123
        print "Successfully sent email"
124
    except:
124
    except:
125
        print "Error: unable to send email."
125
        print "Error: unable to send email."
126
        
126
        
127
def main():
127
def main():
128
    import time
-
 
129
    scrapeBestSellerMobiles()
128
    scrapeBestSellerMobiles()
130
    if len(bestSellers) > 0:
129
    if len(bestSellers) > 0:
131
        resetRanks(3)
130
        resetRanks(3)
132
        time.sleep(20)
-
 
133
        commitBestSellers(3)
131
        commitBestSellers(3)
134
    scrapeBestSellerTablets()
132
    scrapeBestSellerTablets()
135
    if len(bestSellers) > 0:
133
    if len(bestSellers) > 0:
136
        resetRanks(5)
134
        resetRanks(5)
137
        time.sleep(20)
-
 
138
        commitBestSellers(5)
135
        commitBestSellers(5)
139
    sendEmail()
136
    sendEmail()
140
    
137
    
141
if __name__=='__main__':
138
if __name__=='__main__':
142
    main()
139
    main()
143
140