Subversion Repositories SmartDukaan

Rev

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

Rev 14253 Rev 14259
Line 11... Line 11...
11
con = None
11
con = None
12
dealsCatalogIds = []
12
dealsCatalogIds = []
13
itemCatalogMap = {}
13
itemCatalogMap = {}
14
 
14
 
15
parser = optparse.OptionParser()
15
parser = optparse.OptionParser()
16
parser.add_option("-h", "--host", dest="hostname",
16
parser.add_option("-H", "--host", dest="hostname",
17
                      default="localhost",
17
                      default="localhost",
18
                      type="string", help="The HOST where the DB server is running",
18
                      type="string", help="The HOST where the DB server is running",
19
                      metavar="host")
19
                      metavar="db_host")
20
parser.add_option("-m", "--m", dest="mongoHost",
20
parser.add_option("-m", "--m", dest="mongoHost",
21
                      default="localhost",
21
                      default="localhost",
22
                      type="string", help="The HOST where the mongo server is running",
22
                      type="string", help="The HOST where the mongo server is running",
23
                      metavar="mongo_host")
23
                      metavar="mongo_host")
24
 
24
 
Line 35... Line 35...
35
            print e
35
            print e
36
            return None
36
            return None
37
    return con
37
    return con
38
 
38
 
39
def getPrivateDeals():
39
def getPrivateDeals():
-
 
40
    try:
40
    global dealsMap
41
        global dealsMap
41
    dealsMap = dict()
42
        dealsMap = dict()
42
    all_active_items_query =  session.query(PrivateDeals).filter(PrivateDeals.isActive==True).filter(now().between(PrivateDeals.startDate, PrivateDeals.endDate))
43
        all_active_items_query =  session.query(PrivateDeals).filter(PrivateDeals.isActive==True).filter(now().between(PrivateDeals.startDate, PrivateDeals.endDate))
43
    print all_active_items_query
44
        print all_active_items_query
44
    all_active_private_deals = all_active_items_query.all()
45
        all_active_private_deals = all_active_items_query.all()
45
    if all_active_private_deals is not None or all_active_private_deals!=[]:
46
        if all_active_private_deals is not None or all_active_private_deals!=[]:
46
        for active_private_deal in all_active_private_deals:
47
            for active_private_deal in all_active_private_deals:
47
            item = Item.get_by(id = active_private_deal.item_id)
48
                item = Item.get_by(id = active_private_deal.item_id)
48
            if item.sellingPrice >  active_private_deal.dealPrice and item.status==3:
49
                if item.sellingPrice >  active_private_deal.dealPrice and item.status==3:
49
                dealsMap[active_private_deal.item_id] = active_private_deal
50
                    dealsMap[active_private_deal.item_id] = active_private_deal
-
 
51
    finally:
-
 
52
        session.close()
50
 
53
 
51
def getItemsToUpdate():
54
def getItemsToUpdate():
52
    global dealsCatalogIds
55
    global dealsCatalogIds
53
    global itemCatalogMap
56
    global itemCatalogMap
54
    bestSellers = list(get_mongo_connection().Catalog.MasterData.find({'rank':{"$gt":0}}))
57
    bestSellers = list(get_mongo_connection().Catalog.MasterData.find({'rank':{"$gt":0}}))
Line 149... Line 152...
149
    if len(toUpdate) > 0:
152
    if len(toUpdate) > 0:
150
        get_mongo_connection().Catalog.Deals.update({ '_id' : { "$in": toUpdate } }, {'$set':{'showDeal':0 }},upsert=False, multi=True)
153
        get_mongo_connection().Catalog.Deals.update({ '_id' : { "$in": toUpdate } }, {'$set':{'showDeal':0 }},upsert=False, multi=True)
151
        
154
        
152
def main():
155
def main():
153
    getPrivateDeals()
156
    getPrivateDeals()
-
 
157
    try:
154
    getItemsToUpdate()
158
        getItemsToUpdate()
-
 
159
    finally:
-
 
160
        session.close()
155
 
161
 
156
if __name__=='__main__':
162
if __name__=='__main__':
157
    main()
163
    main()
158
164