Subversion Repositories SmartDukaan

Rev

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

Rev 17781 Rev 17933
Line 55... Line 55...
55
    print bundleMap 
55
    print bundleMap 
56
                
56
                
57
 
57
 
58
def addItemIdInfo():
58
def addItemIdInfo():
59
    global bundleMap
59
    global bundleMap
-
 
60
    try:
60
    CatalogDataService.initialize(db_hostname=options.hostname,setup=False)
61
        CatalogDataService.initialize(db_hostname=options.hostname,setup=False)
61
    totalLength = len(bundleMap.keys())
62
        totalLength = len(bundleMap.keys())
62
    fetch =100
63
        fetch =100
63
    start = 0
64
        start = 0
64
    toBreak = False
65
        toBreak = False
65
    while(True):
66
        while(True):
66
        print start
67
            print start
67
        print fetch
68
            print fetch
68
        if fetch > totalLength:
69
            if fetch > totalLength:
69
            fetch = totalLength
70
                fetch = totalLength
70
            toBreak = True
71
                toBreak = True
71
            
72
                
72
        item_list = bundleMap.keys()[start:fetch]
73
            item_list = bundleMap.keys()[start:fetch]
73
        items = session.query(Item,PrivateDeals).outerjoin((PrivateDeals,Item.id==PrivateDeals.item_id)).filter(Item.catalog_item_id.in_(item_list)).all()
74
            items = session.query(Item,PrivateDeals).outerjoin((PrivateDeals,Item.id==PrivateDeals.item_id)).filter(Item.catalog_item_id.in_(item_list)).all()
74
        print items
75
            print items
75
        for i in items:
76
            for i in items:
76
            d_item = i[0]
77
                d_item = i[0]
77
            d_privatedeal = i[1]
78
                d_privatedeal = i[1]
78
            tempList = bundleMap.get(d_item.catalog_item_id)
79
                tempList = bundleMap.get(d_item.catalog_item_id)
79
            sellingPrice = d_item.sellingPrice
80
                sellingPrice = d_item.sellingPrice
80
            sellingPriceType = "Normal"
81
                sellingPriceType = "Normal"
81
            if d_privatedeal is not None and d_privatedeal.isActive==1 and d_privatedeal.startDate < datetime.now() and d_privatedeal.endDate > datetime.now() and d_privatedeal.dealPrice >0:
82
                if d_privatedeal is not None and d_privatedeal.isActive==1 and d_privatedeal.startDate < datetime.now() and d_privatedeal.endDate > datetime.now() and d_privatedeal.dealPrice >0:
82
                sellingPrice = d_privatedeal.dealPrice
83
                    sellingPrice = d_privatedeal.dealPrice
83
                sellingPriceType = "Private deal price"
84
                    sellingPriceType = "Private deal price"
84
            tempList.append({'item_id':d_item.id,'color':d_item.color,'sellingPrice':sellingPrice,'sellingPriceType':sellingPriceType})
85
                tempList.append({'item_id':d_item.id,'color':d_item.color,'sellingPrice':sellingPrice,'sellingPriceType':sellingPriceType})
85
        if toBreak:
86
            if toBreak:
86
            print "Breaking"
87
                print "Breaking"
87
            break
88
                break
88
        start = fetch
89
            start = fetch
89
        fetch = start + fetch
90
            fetch = start + fetch
-
 
91
    finally:
90
    session.close()
92
        session.close()
91
 
93
 
92
def addInfoToMemCache():
94
def addInfoToMemCache():
93
    for k, v in bundleMap.iteritems():
95
    for k, v in bundleMap.iteritems():
94
        for item in v:
96
        for item in v:
95
            availability = inventoryMap.get(item.get('item_id'))
97
            availability = inventoryMap.get(item.get('item_id'))
Line 105... Line 107...
105
        mc.set(str("item_availability_"+str(k)), temp, 24*60*60)
107
        mc.set(str("item_availability_"+str(k)), temp, 24*60*60)
106
 
108
 
107
    
109
    
108
def fetchItemAvailablity():
110
def fetchItemAvailablity():
109
    global inventoryMap
111
    global inventoryMap
-
 
112
    try:
110
    InventoryDataService.initialize(db_hostname=options.hostname,setup=False)
113
        InventoryDataService.initialize(db_hostname=options.hostname,setup=False)
111
    allInventory = session.query(ItemAvailabilityCache).filter(ItemAvailabilityCache.sourceId==1).all()
114
        allInventory = session.query(ItemAvailabilityCache).filter(ItemAvailabilityCache.sourceId==1).all()
112
    for itemInventory in allInventory:
115
        for itemInventory in allInventory:
113
        inventoryMap[itemInventory.itemId] = itemInventory.totalAvailability
116
            inventoryMap[itemInventory.itemId] = itemInventory.totalAvailability
-
 
117
    finally:
114
    session.close()
118
        session.close()
115
 
119
 
116
if __name__ == '__main__':
120
if __name__ == '__main__':
117
    populateSaholicBundles()
121
    populateSaholicBundles()
118
    addItemIdInfo()
122
    addItemIdInfo()
119
    fetchItemAvailablity()
123
    fetchItemAvailablity()