| Line 34... |
Line 34... |
| 34 |
except Exception, e:
|
34 |
except Exception, e:
|
| 35 |
print e
|
35 |
print e
|
| 36 |
return None
|
36 |
return None
|
| 37 |
return con
|
37 |
return con
|
| 38 |
|
38 |
|
| 39 |
def returnLatestPrice(data, source_id):
|
39 |
def returnLatestPrice(data, source_id, ignoreLastUpdated = True):
|
| 40 |
now = datetime.now()
|
40 |
now = datetime.now()
|
| 41 |
if source_id == 1:
|
41 |
if source_id == 1:
|
| 42 |
try:
|
42 |
try:
|
| 43 |
if data['identifier'] is None or len(data['identifier'].strip())==0:
|
43 |
if data['identifier'] is None or len(data['identifier'].strip())==0:
|
| 44 |
return {}
|
44 |
return {}
|
| 45 |
|
45 |
|
| 46 |
if data['dealFlag'] ==1 and data['dealType'] ==1:
|
46 |
if data['dealFlag'] ==1 and data['dealType'] ==1:
|
| 47 |
data['marketPlaceUrl'] = "http://www.amazon.in/dp/%s"%(data['identifier'].strip())
|
47 |
data['marketPlaceUrl'] = "http://www.amazon.in/dp/%s"%(data['identifier'].strip())
|
| 48 |
|
48 |
|
| 49 |
try:
|
49 |
try:
|
| 50 |
if data['priceUpdatedOn'] > to_java_date(now - timedelta(minutes=5)):
|
50 |
if ignoreLastUpdated and data['priceUpdatedOn'] > to_java_date(now - timedelta(minutes=5)):
|
| 51 |
print "sku id is already updated",data['_id']
|
51 |
print "sku id is already updated",data['_id']
|
| 52 |
return {'_id':data['_id'],'available_price':data['available_price'],'in_stock':data['in_stock'],'source_id':1,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail']}
|
52 |
return {'_id':data['_id'],'available_price':data['available_price'],'in_stock':data['in_stock'],'source_id':1,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail']}
|
| 53 |
except:
|
53 |
except:
|
| 54 |
pass
|
54 |
pass
|
| 55 |
|
55 |
|
| Line 94... |
Line 94... |
| 94 |
try:
|
94 |
try:
|
| 95 |
if data['identifier'] is None or len(data['identifier'].strip())==0:
|
95 |
if data['identifier'] is None or len(data['identifier'].strip())==0:
|
| 96 |
return {}
|
96 |
return {}
|
| 97 |
|
97 |
|
| 98 |
try:
|
98 |
try:
|
| 99 |
if data['priceUpdatedOn'] > to_java_date(now - timedelta(minutes=5)):
|
99 |
if ignoreLastUpdated and data['priceUpdatedOn'] > to_java_date(now - timedelta(minutes=5)):
|
| 100 |
print "sku id is already updated",data['_id']
|
100 |
print "sku id is already updated",data['_id']
|
| 101 |
return {'_id':data['_id'],'available_price':data['available_price'],'in_stock':data['in_stock'],'source_id':4,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail']}
|
101 |
return {'_id':data['_id'],'available_price':data['available_price'],'in_stock':data['in_stock'],'source_id':4,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail']}
|
| 102 |
except:
|
102 |
except:
|
| 103 |
pass
|
103 |
pass
|
| 104 |
|
104 |
|
| Line 131... |
Line 131... |
| 131 |
try:
|
131 |
try:
|
| 132 |
if data['identifier'] is None or len(data['identifier'].strip())==0:
|
132 |
if data['identifier'] is None or len(data['identifier'].strip())==0:
|
| 133 |
return {}
|
133 |
return {}
|
| 134 |
|
134 |
|
| 135 |
try:
|
135 |
try:
|
| 136 |
if data['priceUpdatedOn'] > to_java_date(now - timedelta(minutes=5)):
|
136 |
if ignoreLastUpdated and data['priceUpdatedOn'] > to_java_date(now - timedelta(minutes=5)):
|
| 137 |
print "sku id is already updated",data['_id']
|
137 |
print "sku id is already updated",data['_id']
|
| 138 |
return {'_id':data['_id'],'available_price':data['available_price'],'in_stock':data['in_stock'],'source_id':3,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail']}
|
138 |
return {'_id':data['_id'],'available_price':data['available_price'],'in_stock':data['in_stock'],'source_id':3,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail']}
|
| 139 |
|
139 |
|
| 140 |
except Exception as e:
|
140 |
except Exception as e:
|
| 141 |
print "Exception snapdeal"
|
141 |
print "Exception snapdeal"
|
| Line 177... |
Line 177... |
| 177 |
try:
|
177 |
try:
|
| 178 |
if data['identifier'] is None or len(data['identifier'].strip())==0:
|
178 |
if data['identifier'] is None or len(data['identifier'].strip())==0:
|
| 179 |
return {}
|
179 |
return {}
|
| 180 |
|
180 |
|
| 181 |
try:
|
181 |
try:
|
| 182 |
if data['priceUpdatedOn'] > to_java_date(now - timedelta(minutes=5)):
|
182 |
if ignoreLastUpdated and data['priceUpdatedOn'] > to_java_date(now - timedelta(minutes=5)):
|
| 183 |
print "sku id is already updated",data['_id']
|
183 |
print "sku id is already updated",data['_id']
|
| 184 |
return {'_id':data['_id'],'available_price':data['available_price'],'in_stock':data['in_stock'],'source_id':2,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail']}
|
184 |
return {'_id':data['_id'],'available_price':data['available_price'],'in_stock':data['in_stock'],'source_id':2,'source_product_name':data['source_product_name'],'marketPlaceUrl':data['marketPlaceUrl'],'thumbnail':data['thumbnail']}
|
| 185 |
except:
|
185 |
except:
|
| 186 |
pass
|
186 |
pass
|
| 187 |
|
187 |
|
| Line 342... |
Line 342... |
| 342 |
thread.start()
|
342 |
thread.start()
|
| 343 |
except:
|
343 |
except:
|
| 344 |
print "Unable to compute deal for ",item[0]['skuBundleId']
|
344 |
print "Unable to compute deal for ",item[0]['skuBundleId']
|
| 345 |
return info
|
345 |
return info
|
| 346 |
|
346 |
|
| - |
|
347 |
def updatePriceForNotificationBundles(skuBundleId):
|
| - |
|
348 |
itemIds = list(get_mongo_connection().Catalog.MasterData.find({'skuBundleId':skuBundleId,'priceUpdatedOn':{'$lte':to_java_date(datetime.now() - timedelta(minutes=3))}}))
|
| - |
|
349 |
for item in itemIds:
|
| - |
|
350 |
item['dealFlag'] = 0
|
| - |
|
351 |
item['dealType'] = 0
|
| - |
|
352 |
manualDeals = list(get_mongo_connection().Catalog.ManualDeals.find({'startDate':{'$lte':to_java_date(datetime.now())},'endDate':{'$gte':to_java_date(datetime.now())},'source_id':item['source_id'], 'sku':item['_id']}))
|
| - |
|
353 |
if len(manualDeals) > 0:
|
| - |
|
354 |
item['dealFlag'] = 1
|
| - |
|
355 |
item['dealType'] =manualDeals[0]['dealType']
|
| - |
|
356 |
info = returnLatestPrice(item, item['source_id'],False)
|
| - |
|
357 |
print info
|
| - |
|
358 |
try:
|
| - |
|
359 |
thread = threading.Thread(target=recomputeDeal, args = (skuBundleId,))
|
| - |
|
360 |
thread.daemon = True
|
| - |
|
361 |
thread.start()
|
| - |
|
362 |
except:
|
| - |
|
363 |
print "Unable to compute deal for ",skuBundleId
|
| - |
|
364 |
|
| - |
|
365 |
|
| 347 |
def main():
|
366 |
def main():
|
| 348 |
print "retuned %s"%(str(getLatestPrice(1420, 2)))
|
367 |
print "retuned %s"%(str(getLatestPrice(1420, 2)))
|
| 349 |
|
368 |
|
| 350 |
if __name__=='__main__':
|
369 |
if __name__=='__main__':
|
| 351 |
main()
|
370 |
main()
|