Subversion Repositories SmartDukaan

Rev

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

Rev 15419 Rev 15524
Line 38... Line 38...
38
amazonAsinPrice={}
38
amazonAsinPrice={}
39
amazonLongTermActivePromotions = {}
39
amazonLongTermActivePromotions = {}
40
amazonShortTermActivePromotions = {}
40
amazonShortTermActivePromotions = {}
41
wpiTodayExpiry = {}
41
wpiTodayExpiry = {}
42
notListed = []
42
notListed = []
-
 
43
toList = []
43
saleMap = {}
44
saleMap = {}
44
monthlySaleMap = {}
45
monthlySaleMap = {}
45
categoryMap = {}
46
categoryMap = {}
46
latestHourlySnapshot = {}
47
latestHourlySnapshot = {}
47
exceptionMap = {1:'WANLC is 0',2:'Unable to fetch our price',3:'No other seller or Unable to fetch competitive pricing',
48
exceptionMap = {1:'WANLC is 0',2:'Unable to fetch our price',3:'No other seller or Unable to fetch competitive pricing',
Line 525... Line 526...
525
        
526
        
526
def populateStuff(time,runType):
527
def populateStuff(time,runType):
527
    global amazonLongTermActivePromotions
528
    global amazonLongTermActivePromotions
528
    global amazonShortTermActivePromotions
529
    global amazonShortTermActivePromotions
529
    global wpiTodayExpiry
530
    global wpiTodayExpiry
-
 
531
    global toList
530
    itemInfo = []
532
    itemInfo = []
531
    inventory_client = InventoryClient().get_client()
533
    inventory_client = InventoryClient().get_client()
532
    fbaAvailableInventorySnapshot = inventory_client.getAllAvailableAmazonFbaItemInventory()
534
    fbaAvailableInventorySnapshot = inventory_client.getAllAvailableAmazonFbaItemInventory()
533
    if runType=='FAVOURITE':
535
    if runType=='FAVOURITE':
534
        favourites = session.query(Amazonlisted.itemId).filter(or_(Amazonlisted.autoFavourite==True, Amazonlisted.manualFavourite==True)).all()
536
        favourites = session.query(Amazonlisted.itemId).filter(or_(Amazonlisted.autoFavourite==True, Amazonlisted.manualFavourite==True)).all()
535
    for fbaInventoryItem in fbaAvailableInventorySnapshot:
537
    for fbaInventoryItem in fbaAvailableInventorySnapshot:
536
        if runType=='FAVOURITE':
538
        if runType=='FAVOURITE':
537
            if not (fbaInventoryItem.item_id in favourites):
539
            if not (fbaInventoryItem.item_id in favourites):
538
                continue 
540
                continue 
539
        d_amazon_listed = Amazonlisted.get_by(itemId=fbaInventoryItem.item_id)
541
        d_amazon_listed = Amazonlisted.get_by(itemId=fbaInventoryItem.item_id)
-
 
542
        if fbaInventoryItem.location==0:
-
 
543
            if not d_amazon_listed.isFba:
-
 
544
                sku = 'FBA'+str(fbaInventoryItem.item_id)
-
 
545
                toList.append(sku)
-
 
546
        elif fbaInventoryItem.location==1:
-
 
547
            if not d_amazon_listed.isFbb:
-
 
548
                sku = 'FBB'+str(fbaInventoryItem.item_id)
-
 
549
                toList.append(sku)
-
 
550
        elif fbaInventoryItem.location==2:
-
 
551
            if not d_amazon_listed.isFbg:
-
 
552
                sku = 'FBG'+str(fbaInventoryItem.item_id)
-
 
553
                toList.append(sku)
-
 
554
        else:
-
 
555
            pass
540
        if d_amazon_listed is None:
556
        if d_amazon_listed is None:
541
            if fbaInventoryItem.location==0:
557
            if fbaInventoryItem.location==0:
542
                sku = 'FBA'+str(fbaInventoryItem.item_id)
558
                sku = 'FBA'+str(fbaInventoryItem.item_id)
543
                notListed.append(sku)
559
                notListed.append(sku)
544
            elif fbaInventoryItem.location==1:
560
            elif fbaInventoryItem.location==1:
Line 3147... Line 3163...
3147
            amItem.fbgPriceLastUpdatedOn = datetime.now()
3163
            amItem.fbgPriceLastUpdatedOn = datetime.now()
3148
        else:
3164
        else:
3149
            continue
3165
            continue
3150
    session.commit()
3166
    session.commit()
3151
    
3167
    
-
 
3168
def fixListingAnomaly():
-
 
3169
    for sku in toList:
-
 
3170
        if sku.startswith('FBA'):
-
 
3171
            am_listed = Amazonlisted.get_by(itemId=sku[3:])
-
 
3172
            am_listed.isFba = True
-
 
3173
        elif sku.startswith('FBB'):
-
 
3174
            am_listed = Amazonlisted.get_by(itemId=sku[3:])
-
 
3175
            am_listed.isFbb = True
-
 
3176
        elif sku.startswith('FBG'):
-
 
3177
            am_listed = Amazonlisted.get_by(itemId=sku[3:])
-
 
3178
            am_listed.isFbg = True
-
 
3179
        else:
-
 
3180
            pass
-
 
3181
    session.commit()
3152
 
3182
 
3153
def main():
3183
def main():
3154
    parser = optparse.OptionParser()
3184
    parser = optparse.OptionParser()
3155
    parser.add_option("-t", "--type", dest="runType",
3185
    parser.add_option("-t", "--type", dest="runType",
3156
                   default="FULL", type="string",
3186
                   default="FULL", type="string",
Line 3162... Line 3192...
3162
    time.sleep(5)
3192
    time.sleep(5)
3163
    timestamp = datetime.now()
3193
    timestamp = datetime.now()
3164
    generateCategoryMap()
3194
    generateCategoryMap()
3165
    fetchFbaSale()
3195
    fetchFbaSale()
3166
    itemInfo = populateStuff(timestamp,options.runType)
3196
    itemInfo = populateStuff(timestamp,options.runType)
-
 
3197
    try:
-
 
3198
        fixListingAnomaly()
-
 
3199
    except:
-
 
3200
        pass
3167
    itemsToPopulate = 0
3201
    itemsToPopulate = 0
3168
    toSync = 0
3202
    toSync = 0
3169
    lenItems = len(itemInfo)
3203
    lenItems = len(itemInfo)
3170
    while(toSync < lenItems):
3204
    while(toSync < lenItems):
3171
        oldSync = toSync
3205
        oldSync = toSync