Subversion Repositories SmartDukaan

Rev

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

Rev 14261 Rev 14325
Line 5... Line 5...
5
from datetime import datetime, timedelta
5
from datetime import datetime, timedelta
6
import time
6
import time
7
from multiprocessing import Pool as ThreadPool
7
from multiprocessing import Pool as ThreadPool
8
from multiprocessing import cpu_count
8
from multiprocessing import cpu_count
9
import optparse
9
import optparse
-
 
10
from dtr.storage.MemCache import MemCache
10
 
11
 
11
con = None
12
con = None
12
 
13
 
13
parser = optparse.OptionParser()
14
parser = optparse.OptionParser()
14
parser.add_option("-m", "--m", dest="mongoHost",
15
parser.add_option("-m", "--m", dest="mongoHost",
Line 16... Line 17...
16
                      type="string", help="The HOST where the mongo server is running",
17
                      type="string", help="The HOST where the mongo server is running",
17
                      metavar="mongo_host")
18
                      metavar="mongo_host")
18
 
19
 
19
(options, args) = parser.parse_args()
20
(options, args) = parser.parse_args()
20
 
21
 
-
 
22
mc = MemCache(options.mongoHost)
21
 
23
 
22
headers = { 
24
headers = { 
23
           'User-agent':'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11',
25
           'User-agent':'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11',
24
            'Accept' : 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',      
26
            'Accept' : 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',      
25
            'Accept-Language' : 'en-US,en;q=0.8',                     
27
            'Accept-Language' : 'en-US,en;q=0.8',                     
Line 112... Line 114...
112
    try:
114
    try:
113
        recomputeDeal(data['skuBundleId'])
115
        recomputeDeal(data['skuBundleId'])
114
    except:
116
    except:
115
        print "Unable to compute deal for ",data['skuBundleId']
117
        print "Unable to compute deal for ",data['skuBundleId']
116
    
118
    
-
 
119
 
-
 
120
def populateNegativeDeals():
-
 
121
    negativeDeals = get_mongo_connection().Catalog.NegativeDeals.find().distinct('sku')
-
 
122
    mc.set("negative_deals", negativeDeals, 600) 
117
    
123
    
118
def recomputeDeal(skuBundleId):
124
def recomputeDeal(skuBundleId):
119
    """Lets recompute deal for this bundle"""
125
    """Lets recompute deal for this bundle"""
120
    print "Recomputing for bundleId",skuBundleId
126
    print "Recomputing for bundleId",skuBundleId
121
    
127
    
Line 123... Line 129...
123
    bestPrice = float("inf")
129
    bestPrice = float("inf")
124
    bestOne = None
130
    bestOne = None
125
    bestSellerPoints = 0
131
    bestSellerPoints = 0
126
    toUpdate = []
132
    toUpdate = []
127
    for similarItem in similarItems:
133
    for similarItem in similarItems:
-
 
134
        if mc.get("negativeDeals") is None:
-
 
135
            populateNegativeDeals()
128
        if similarItem['in_stock'] == 0 or similarItem['maxprice'] is None or similarItem['maxprice'] < similarItem['available_price']:
136
        if similarItem['in_stock'] == 0 or similarItem['maxprice'] is None or similarItem['maxprice'] < similarItem['available_price'] or similarItem['_id'] in mc.get("negativeDeals"):
129
            get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0 }})
137
            get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0 }})
130
            continue
138
            continue
131
        if similarItem['available_price'] < bestPrice:
139
        if similarItem['available_price'] < bestPrice:
132
            bestOne = similarItem
140
            bestOne = similarItem
133
            bestPrice = similarItem['available_price']
141
            bestPrice = similarItem['available_price']