| Line 9... |
Line 9... |
| 9 |
|
9 |
|
| 10 |
dealsMap = {}
|
10 |
dealsMap = {}
|
| 11 |
con = None
|
11 |
con = None
|
| 12 |
dealsCatalogIds = []
|
12 |
dealsCatalogIds = []
|
| 13 |
itemCatalogMap = {}
|
13 |
itemCatalogMap = {}
|
| 14 |
timestamp = datetime.now()
|
- |
|
| 15 |
print to_java_date(timestamp)
|
- |
|
| 16 |
|
14 |
|
| 17 |
parser = optparse.OptionParser()
|
15 |
parser = optparse.OptionParser()
|
| 18 |
parser.add_option("-H", "--host", dest="hostname",
|
16 |
parser.add_option("-H", "--host", dest="hostname",
|
| 19 |
default="localhost",
|
17 |
default="localhost",
|
| 20 |
type="string", help="The HOST where the DB server is running",
|
18 |
type="string", help="The HOST where the DB server is running",
|
| Line 35... |
Line 33... |
| 35 |
return con
|
33 |
return con
|
| 36 |
|
34 |
|
| 37 |
def getPrivateDeals():
|
35 |
def getPrivateDeals():
|
| 38 |
global dealsMap
|
36 |
global dealsMap
|
| 39 |
dealsMap = dict()
|
37 |
dealsMap = dict()
|
| 40 |
all_active_items_query = session.query(PrivateDeals).filter(PrivateDeals.isActive==True).filter(now().between(PrivateDeals.startDate, PrivateDeals.endDate + timedelta(days=0)))
|
38 |
all_active_items_query = session.query(PrivateDeals).filter(PrivateDeals.isActive==True).filter(now().between(PrivateDeals.startDate, PrivateDeals.endDate))
|
| - |
|
39 |
print all_active_items_query
|
| 41 |
all_active_private_deals = all_active_items_query.all()
|
40 |
all_active_private_deals = all_active_items_query.all()
|
| 42 |
if all_active_private_deals is not None or all_active_private_deals!=[]:
|
41 |
if all_active_private_deals is not None or all_active_private_deals!=[]:
|
| 43 |
for active_private_deal in all_active_private_deals:
|
42 |
for active_private_deal in all_active_private_deals:
|
| 44 |
item = Item.get_by(id = active_private_deal.item_id)
|
43 |
item = Item.get_by(id = active_private_deal.item_id)
|
| 45 |
if item.sellingPrice > active_private_deal.dealPrice and item.status==3:
|
44 |
if item.sellingPrice > active_private_deal.dealPrice and item.status==3:
|
| 46 |
dealsMap[active_private_deal.item_id] = active_private_deal
|
45 |
dealsMap[active_private_deal.item_id] = active_private_deal
|
| 47 |
|
46 |
|
| 48 |
def getItemsToUpdate():
|
47 |
def getItemsToUpdate():
|
| 49 |
global dealsCatalogIds
|
48 |
global dealsCatalogIds
|
| 50 |
global itemCatalogMap
|
49 |
global itemCatalogMap
|
| 51 |
saholicCatalogIds = list(get_mongo_connection().Catalog.MasterData.find({'rank':{"$gt":0},'source_id':4}))
|
50 |
saholicCatalogIds = list(get_mongo_connection().Catalog.MasterData.find({'rank':{"$gt":0}}))
|
| 52 |
for d in saholicCatalogIds:
|
51 |
for d in saholicCatalogIds:
|
| - |
|
52 |
if d['source_id']!=4:
|
| - |
|
53 |
continue
|
| 53 |
dealsCatalogIds.append(long(d['identifier'].strip()))
|
54 |
dealsCatalogIds.append(long(d['identifier'].strip()))
|
| 54 |
items = Item.query.filter(Item.catalog_item_id.in_(dealsCatalogIds)).all()
|
55 |
items = Item.query.filter(Item.catalog_item_id.in_(dealsCatalogIds)).all()
|
| 55 |
for item in items:
|
56 |
for item in items:
|
| 56 |
temp = []
|
57 |
temp = []
|
| 57 |
if not itemCatalogMap.has_key(item.catalog_item_id):
|
58 |
if not itemCatalogMap.has_key(item.catalog_item_id):
|
| Line 89... |
Line 90... |
| 89 |
print in_stock
|
90 |
print in_stock
|
| 90 |
print available_price
|
91 |
print available_price
|
| 91 |
print dealsMap.get(d_item.id)
|
92 |
print dealsMap.get(d_item.id)
|
| 92 |
print "++++++++++++++++++++++++++"
|
93 |
print "++++++++++++++++++++++++++"
|
| 93 |
if available_price > 0 or available_price is not None:
|
94 |
if available_price > 0 or available_price is not None:
|
| 94 |
get_mongo_connection().Catalog.MasterData.update({'_id':saholicCatalogId['_id']}, {'$set' : {'available_price':available_price,'updatedOn':to_java_date(timestamp),'priceUpdatedOn':to_java_date(timestamp),'in_stock':in_stock}}, multi=True)
|
95 |
get_mongo_connection().Catalog.MasterData.update({'_id':saholicCatalogId['_id']}, {'$set' : {'available_price':available_price,'updatedOn':to_java_date(datetime.now()),'priceUpdatedOn':to_java_date(datetime.now()),'in_stock':in_stock}}, multi=True)
|
| 95 |
get_mongo_connection().Catalog.Deals.update({'_id':saholicCatalogId['_id']}, {'$set' : {'available_price':available_price , 'in_stock':in_stock}}, multi=True)
|
96 |
get_mongo_connection().Catalog.Deals.update({'_id':saholicCatalogId['_id']}, {'$set' : {'available_price':available_price , 'in_stock':in_stock}}, multi=True)
|
| 96 |
else:
|
97 |
else:
|
| 97 |
get_mongo_connection().Catalog.MasterData.update({'_id':saholicCatalogId['_id']}, {'$set' : {'updatedOn':to_java_date(timestamp),'in_stock':in_stock,'priceUpdatedOn':to_java_date(timestamp)}}, multi=True)
|
98 |
get_mongo_connection().Catalog.MasterData.update({'_id':saholicCatalogId['_id']}, {'$set' : {'updatedOn':to_java_date(datetime.now()),'in_stock':in_stock,'priceUpdatedOn':to_java_date(datetime.now())}}, multi=True)
|
| 98 |
get_mongo_connection().Catalog.Deals.update({'_id':saholicCatalogId['_id']}, {'$set' : {'in_stock':in_stock}}, multi=True)
|
99 |
get_mongo_connection().Catalog.Deals.update({'_id':saholicCatalogId['_id']}, {'$set' : {'in_stock':in_stock}}, multi=True)
|
| 99 |
|
100 |
|
| 100 |
try:
|
101 |
try:
|
| 101 |
recomputeDeal(saholicCatalogId['skuBundleId'])
|
102 |
recomputeDeal(saholicCatalogId['skuBundleId'])
|
| 102 |
except:
|
103 |
except:
|
| Line 133... |
Line 134... |
| 133 |
if len(toUpdate) > 0:
|
134 |
if len(toUpdate) > 0:
|
| 134 |
get_mongo_connection().Catalog.Deals.update({ '_id' : { "$in": toUpdate } }, {'$set':{'showDeal':0 }},upsert=False, multi=True)
|
135 |
get_mongo_connection().Catalog.Deals.update({ '_id' : { "$in": toUpdate } }, {'$set':{'showDeal':0 }},upsert=False, multi=True)
|
| 135 |
|
136 |
|
| 136 |
def main():
|
137 |
def main():
|
| 137 |
getPrivateDeals()
|
138 |
getPrivateDeals()
|
| 138 |
getItemsToUpdate()
|
139 |
x = dealsMap.values()
|
| - |
|
140 |
z = sorted(x, key = lambda x: (x.item_id))
|
| - |
|
141 |
for m in z:
|
| - |
|
142 |
print m.item_id
|
| 139 |
|
143 |
|
| 140 |
if __name__=='__main__':
|
144 |
if __name__=='__main__':
|
| 141 |
main()
|
145 |
main()
|
| 142 |
|
146 |
|