| Line 40... |
Line 40... |
| 40 |
syncPrice=config_client.get_property('sync_price_on_marketplace')
|
40 |
syncPrice=config_client.get_property('sync_price_on_marketplace')
|
| 41 |
|
41 |
|
| 42 |
|
42 |
|
| 43 |
DataService.initialize(db_hostname=host)
|
43 |
DataService.initialize(db_hostname=host)
|
| 44 |
|
44 |
|
| 45 |
threads = []
|
- |
|
| 46 |
inventoryMap = {}
|
45 |
inventoryMap = {}
|
| 47 |
itemSaleMap = {}
|
46 |
itemSaleMap = {}
|
| 48 |
cantCompete, buyBoxItems, competitive, competitiveNoInventory, exceptionItems, negativeMargin, cheapButNotPref, prefButNotCheap = [],[],[],[],[],[],[],[]
|
- |
|
| 49 |
scraper = FlipkartScraper.FlipkartScraper()
|
47 |
scraper = FlipkartScraper.FlipkartScraper()
|
| 50 |
|
48 |
testcount = 0
|
| 51 |
|
49 |
|
| 52 |
class __FlipkartDetails:
|
50 |
class __FlipkartDetails:
|
| 53 |
|
51 |
|
| 54 |
def __init__(self,rank ,ourSp , secondLowestSellerSp, prefSellerSp, lowestSellerSp, lowestSellerScore, prefSellerScore, secondLowestSellerScore, ourScore, shippingTimeLowerLimitLowestSeller,shippingTimeUpperLimitLowestSeller, \
|
52 |
def __init__(self,rank ,ourSp , secondLowestSellerSp, prefSellerSp, lowestSellerSp, lowestSellerScore, prefSellerScore, secondLowestSellerScore, ourScore, shippingTimeLowerLimitLowestSeller,shippingTimeUpperLimitLowestSeller, \
|
| 55 |
shippingTimeLowerLimitPrefSeller, shippingTimeUpperLimitPrefSeller, shippingTimeLowerLimitOur, shippingTimeUpperLimitOur, shippingTimeLowerLimitSecondLowestSeller, shippingTimeUpperLimitSecondLowestSeller, totalAvailableSeller, lowestSellerName, lowestSellerCode, secondLowestSellerName, secondLowestSellerCode, prefSellerName, prefSellerCode, lowestSellerBuyTrend, \
|
53 |
shippingTimeLowerLimitPrefSeller, shippingTimeUpperLimitPrefSeller, shippingTimeLowerLimitOur, shippingTimeUpperLimitOur, shippingTimeLowerLimitSecondLowestSeller, shippingTimeUpperLimitSecondLowestSeller, totalAvailableSeller, lowestSellerName, lowestSellerCode, secondLowestSellerName, secondLowestSellerCode, prefSellerName, prefSellerCode, lowestSellerBuyTrend, \
|
| Line 85... |
Line 83... |
| 85 |
self.secondLowestSellerBuyTrend = secondLowestSellerBuyTrend
|
83 |
self.secondLowestSellerBuyTrend = secondLowestSellerBuyTrend
|
| 86 |
self.ourCode = ourCode
|
84 |
self.ourCode = ourCode
|
| 87 |
|
85 |
|
| 88 |
class __FlipkartItemInfo:
|
86 |
class __FlipkartItemInfo:
|
| 89 |
|
87 |
|
| 90 |
def __init__(self, fkSerialNumber, nlc, courierCost, item_id, product_group, brand, model_name, model_number, color, weight, parent_category, risky, warehouseId, vatRate, runType, parent_category_name, sourcePercentage, ourFlipkartInventory, skuAtFlipkart):
|
88 |
def __init__(self, fkSerialNumber, nlc, courierCost, item_id, product_group, brand, model_name, model_number, color, weight, parent_category, risky, warehouseId, vatRate, runType, parent_category_name, sourcePercentage, ourFlipkartInventory, skuAtFlipkart, flipkartDetails):
|
| 91 |
|
89 |
|
| 92 |
self.fkSerialNumber = fkSerialNumber
|
90 |
self.fkSerialNumber = fkSerialNumber
|
| 93 |
self.nlc = nlc
|
91 |
self.nlc = nlc
|
| 94 |
self.courierCost = courierCost
|
92 |
self.courierCost = courierCost
|
| 95 |
self.item_id = item_id
|
93 |
self.item_id = item_id
|
| Line 105... |
Line 103... |
| 105 |
self.vatRate = vatRate
|
103 |
self.vatRate = vatRate
|
| 106 |
self.runType = runType
|
104 |
self.runType = runType
|
| 107 |
self.parent_category_name = parent_category_name
|
105 |
self.parent_category_name = parent_category_name
|
| 108 |
self.sourcePercentage = sourcePercentage
|
106 |
self.sourcePercentage = sourcePercentage
|
| 109 |
self.ourFlipkartInventory = ourFlipkartInventory
|
107 |
self.ourFlipkartInventory = ourFlipkartInventory
|
| 110 |
self.skuAtFlipkart = skuAtFlipkart
|
108 |
self.skuAtFlipkart = skuAtFlipkart
|
| - |
|
109 |
self.flipkartDetails = flipkartDetails
|
| 111 |
|
110 |
|
| 112 |
class __FlipkartPricing:
|
111 |
class __FlipkartPricing:
|
| 113 |
|
112 |
|
| 114 |
def __init__(self, ourSp, ourTp, lowestTp, lowestPossibleTp, secondLowestSellerTp, lowestPossibleSp, prefSellerTp):
|
113 |
def __init__(self, ourSp, ourTp, lowestTp, lowestPossibleTp, secondLowestSellerTp, lowestPossibleSp, prefSellerTp):
|
| 115 |
self.ourTp = ourTp
|
114 |
self.ourTp = ourTp
|
| Line 656... |
Line 655... |
| 656 |
# r = requests.get(request_url, auth=('m2z93iskuj81qiid', '0c7ab6a5-98c0-4cdc-8be3-72c591e0add4'))
|
655 |
# r = requests.get(request_url, auth=('m2z93iskuj81qiid', '0c7ab6a5-98c0-4cdc-8be3-72c591e0add4'))
|
| 657 |
# print "Inventory info",r.json()
|
656 |
# print "Inventory info",r.json()
|
| 658 |
# stock_count = int((r.json()['attributeValues'])['stock_count'])
|
657 |
# stock_count = int((r.json()['attributeValues'])['stock_count'])
|
| 659 |
# except:
|
658 |
# except:
|
| 660 |
# stock_count = 0
|
659 |
# stock_count = 0
|
| 661 |
flipkartItemInfo = __FlipkartItemInfo(flipkart_item.flipkartSerialNumber, flipkart_item.maxNlc,mp_item.courierCost, it.id, it.product_group, it.brand, it.model_name, it.model_number, it.color, it.weight, category.parent_category_id, it.risky, flipkart_item.warehouseId, None, runType, parent_category.display_name,sourcePercentage,None,flipkart_item.skuAtFlipkart)
|
660 |
flipkartItemInfo = __FlipkartItemInfo(flipkart_item.flipkartSerialNumber, flipkart_item.maxNlc,mp_item.courierCost, it.id, it.product_group, it.brand, it.model_name, it.model_number, it.color, it.weight, category.parent_category_id, it.risky, flipkart_item.warehouseId, None, runType, parent_category.display_name,sourcePercentage,None,flipkart_item.skuAtFlipkart,None)
|
| 662 |
itemInfo.append(flipkartItemInfo)
|
661 |
itemInfo.append(flipkartItemInfo)
|
| 663 |
return itemInfo
|
662 |
return itemInfo
|
| 664 |
|
663 |
|
| 665 |
def fetchDetails(flipkartSerialNumber,scraper):
|
664 |
def fetchDetails(flipkartSerialNumber,scraper):
|
| 666 |
url = "http://www.flipkart.com/ps/%s"%(flipkartSerialNumber)
|
665 |
url = "http://www.flipkart.com/ps/%s"%(flipkartSerialNumber)
|
| Line 773... |
Line 772... |
| 773 |
elif (float(lowestSellingPrice - ourNlc))/lowestSellingPrice >=0 and (float(lowestSellingPrice - ourNlc))/lowestSellingPrice <=.02:
|
772 |
elif (float(lowestSellingPrice - ourNlc))/lowestSellingPrice >=0 and (float(lowestSellingPrice - ourNlc))/lowestSellingPrice <=.02:
|
| 774 |
return 'MEDIUM'
|
773 |
return 'MEDIUM'
|
| 775 |
else:
|
774 |
else:
|
| 776 |
return 'LOW'
|
775 |
return 'LOW'
|
| 777 |
|
776 |
|
| 778 |
def decideCategory(val):
|
777 |
def decideCategory(itemInfo):
|
| 779 |
print type(val)
|
778 |
print "length****",len(itemInfo)
|
| 780 |
print val
|
- |
|
| 781 |
print "dusdlsdkskd"
|
- |
|
| 782 |
global itemSaleMap
|
779 |
global itemSaleMap
|
| 783 |
global cantCompete
|
- |
|
| 784 |
global buyBoxItems
|
- |
|
| 785 |
global competitive
|
780 |
|
| 786 |
global competitiveNoInventory
|
781 |
cantCompete, buyBoxItems, competitive, competitiveNoInventory, exceptionItems, negativeMargin, cheapButNotPref, prefButNotCheap = [],[],[],[],[],[],[],[]
|
| 787 |
global exceptionItems
|
- |
|
| 788 |
global negativeMargin
|
- |
|
| 789 |
global cheapButNotPref
|
- |
|
| 790 |
global prefButNotCheap
|
- |
|
| 791 |
|
782 |
|
| 792 |
catalog_client = CatalogClient().get_client()
|
783 |
catalog_client = CatalogClient().get_client()
|
| 793 |
inventory_client = InventoryClient().get_client()
|
784 |
inventory_client = InventoryClient().get_client()
|
| 794 |
|
785 |
|
| 795 |
spm = val.sourcePercentage
|
786 |
for val in itemInfo:
|
| 796 |
#print "Fetching details of ",val.fkSerialNumber
|
787 |
spm = val.sourcePercentage
|
| 797 |
#flipkartDetails = fetchDetails(val.fkSerialNumber,scraper)
|
788 |
flipkartDetails = val.flipkartDetails
|
| 798 |
try:
|
789 |
#print "Fetching details of ",val.fkSerialNumber
|
| 799 |
flipkartDetails = fetchDetails(val.fkSerialNumber,scraper)
|
790 |
#flipkartDetails = fetchDetails(val.fkSerialNumber,scraper)
|
| 800 |
except Exception as e:
|
791 |
|
| 801 |
print "Unable to fetch details of",val.fkSerialNumber
|
792 |
if (flipkartDetails.totalAvailableSeller==0):
|
| 802 |
print e
|
793 |
exceptionItems.append(val)
|
| 803 |
exceptionItems.append(val)
|
794 |
continue
|
| 804 |
return
|
795 |
|
| 805 |
|
796 |
mpItem = MarketplaceItems.get_by(itemId=val.item_id,source=OrderSource.FLIPKART)
|
| 806 |
try:
|
797 |
warehouse = inventory_client.getWarehouse(val.warehouseId)
|
| 807 |
request_url = "https://api.flipkart.net/sellers/skus/%s/listings"%(str(val.skuAtFlipkart))
|
798 |
|
| 808 |
r = requests.get(request_url, auth=('m2z93iskuj81qiid', '0c7ab6a5-98c0-4cdc-8be3-72c591e0add4'))
|
799 |
itemSaleList = []
|
| 809 |
print "Inventory info",r.json()
|
800 |
oosForAllSources = inventory_client.getOosStatusesForXDaysForItem(val.item_id, 0, 3)
|
| 810 |
stock_count = int((r.json()['attributeValues'])['stock_count'])
|
801 |
oosForFlipkart = inventory_client.getOosStatusesForXDaysForItem(val.item_id, OrderSource.FLIPKART, 5)
|
| 811 |
except:
|
802 |
oosForFlipkartLastDay = inventory_client.getOosStatusesForXDaysForItem(val.item_id, OrderSource.FLIPKART, 1)
|
| 812 |
stock_count = 0
|
803 |
itemSaleList.append(oosForAllSources)
|
| 813 |
|
804 |
itemSaleList.append(oosForFlipkart)
|
| 814 |
val.ourFlipkartInventory = stock_count
|
805 |
itemSaleList.append(calculateAverageSale(oosForAllSources))
|
| 815 |
|
806 |
itemSaleList.append(calculateAverageSale(oosForFlipkart))
|
| 816 |
if (flipkartDetails.totalAvailableSeller==0):
|
807 |
itemSaleList.append(calculateAverageSale(oosForFlipkartLastDay))
|
| 817 |
exceptionItems.append(val)
|
808 |
itemSaleList.append(calculateTotalSale(oosForFlipkart))
|
| 818 |
return
|
809 |
itemSaleMap[val.item_id]=itemSaleList
|
| 819 |
|
810 |
|
| 820 |
mpItem = MarketplaceItems.get_by(itemId=val.item_id,source=OrderSource.FLIPKART)
|
811 |
if flipkartDetails.rank==0:
|
| 821 |
warehouse = inventory_client.getWarehouse(val.warehouseId)
|
812 |
flipkartDetails.ourSp = mpItem.currentSp
|
| 822 |
|
813 |
ourSp = mpItem.currentSp
|
| 823 |
itemSaleList = []
|
814 |
else:
|
| 824 |
oosForAllSources = inventory_client.getOosStatusesForXDaysForItem(val.item_id, 0, 3)
|
815 |
ourSp = flipkartDetails.ourSp
|
| 825 |
oosForFlipkart = inventory_client.getOosStatusesForXDaysForItem(val.item_id, OrderSource.FLIPKART, 5)
|
816 |
vatRate = catalog_client.getVatPercentageForItem(val.item_id, warehouse.stateId, flipkartDetails.ourSp)
|
| 826 |
oosForFlipkartLastDay = inventory_client.getOosStatusesForXDaysForItem(val.item_id, OrderSource.FLIPKART, 1)
|
817 |
val.vatRate = vatRate
|
| 827 |
itemSaleList.append(oosForAllSources)
|
818 |
if (flipkartDetails.ourBuyTrend == 'PrefCheap') or (flipkartDetails.rank==1 and flipkartDetails.totalAvailableSeller==1):
|
| 828 |
itemSaleList.append(oosForFlipkart)
|
819 |
temp=[]
|
| 829 |
itemSaleList.append(calculateAverageSale(oosForAllSources))
|
820 |
temp.append(flipkartDetails)
|
| 830 |
itemSaleList.append(calculateAverageSale(oosForFlipkart))
|
821 |
temp.append(val)
|
| 831 |
itemSaleList.append(calculateAverageSale(oosForFlipkartLastDay))
|
822 |
secondLowestTp=0 if flipkartDetails.totalAvailableSeller==1 else getOtherTp(flipkartDetails,val,spm,False)
|
| 832 |
itemSaleList.append(calculateTotalSale(oosForFlipkart))
|
823 |
prefSellerTp=0 if flipkartDetails.totalAvailableSeller < 2 else getOtherTp(flipkartDetails,val,spm,True)
|
| 833 |
itemSaleMap[val.item_id]=itemSaleList
|
824 |
flipkartPricing = __FlipkartPricing(flipkartDetails.ourSp,getOurTp(flipkartDetails,val,spm,mpItem),None,getLowestPossibleTp(flipkartDetails,val,spm,mpItem),secondLowestTp,getLowestPossibleSp(flipkartDetails,val,spm,mpItem),prefSellerTp)
|
| 834 |
|
825 |
temp.append(flipkartPricing)
|
| 835 |
if flipkartDetails.rank==0:
|
826 |
temp.append(mpItem)
|
| 836 |
flipkartDetails.ourSp = mpItem.currentSp
|
827 |
buyBoxItems.append(temp)
|
| 837 |
ourSp = mpItem.currentSp
|
828 |
continue
|
| 838 |
else:
|
829 |
|
| 839 |
ourSp = flipkartDetails.ourSp
|
830 |
if (flipkartDetails.ourBuyTrend == 'PrefNCheap'):
|
| 840 |
vatRate = catalog_client.getVatPercentageForItem(val.item_id, warehouse.stateId, flipkartDetails.ourSp)
|
831 |
temp=[]
|
| 841 |
val.vatRate = vatRate
|
832 |
temp.append(flipkartDetails)
|
| 842 |
if (flipkartDetails.ourBuyTrend == 'PrefCheap') or (flipkartDetails.rank==1 and flipkartDetails.totalAvailableSeller==1):
|
833 |
temp.append(val)
|
| 843 |
temp=[]
|
834 |
secondLowestTp=0 if flipkartDetails.totalAvailableSeller==1 else getOtherTp(flipkartDetails,val,spm,False)
|
| 844 |
temp.append(flipkartDetails)
|
835 |
prefSellerTp=0 if flipkartDetails.totalAvailableSeller < 2 else getOtherTp(flipkartDetails,val,spm,True)
|
| 845 |
temp.append(val)
|
836 |
flipkartPricing = __FlipkartPricing(flipkartDetails.ourSp,getOurTp(flipkartDetails,val,spm,mpItem),None,getLowestPossibleTp(flipkartDetails,val,spm,mpItem),secondLowestTp,getLowestPossibleSp(flipkartDetails,val,spm,mpItem),prefSellerTp)
|
| 846 |
secondLowestTp=0 if flipkartDetails.totalAvailableSeller==1 else getOtherTp(flipkartDetails,val,spm,False)
|
837 |
temp.append(flipkartPricing)
|
| 847 |
prefSellerTp=0 if flipkartDetails.totalAvailableSeller < 2 else getOtherTp(flipkartDetails,val,spm,True)
|
838 |
temp.append(mpItem)
|
| 848 |
flipkartPricing = __FlipkartPricing(flipkartDetails.ourSp,getOurTp(flipkartDetails,val,spm,mpItem),None,getLowestPossibleTp(flipkartDetails,val,spm,mpItem),secondLowestTp,getLowestPossibleSp(flipkartDetails,val,spm,mpItem),prefSellerTp)
|
839 |
prefButNotCheap.append(temp)
|
| 849 |
temp.append(flipkartPricing)
|
840 |
continue
|
| 850 |
temp.append(mpItem)
|
841 |
|
| 851 |
buyBoxItems.append(temp)
|
842 |
if (flipkartDetails.ourBuyTrend == 'NPrefCheap') and (flipkartDetails.rank==1):
|
| 852 |
return
|
843 |
temp=[]
|
| 853 |
|
844 |
temp.append(flipkartDetails)
|
| 854 |
if (flipkartDetails.ourBuyTrend == 'PrefNCheap'):
|
845 |
temp.append(val)
|
| 855 |
temp=[]
|
846 |
prefSellerTp=0 if flipkartDetails.totalAvailableSeller < 2 else getOtherTp(flipkartDetails,val,spm,True)
|
| 856 |
temp.append(flipkartDetails)
|
847 |
flipkartPricing = __FlipkartPricing(flipkartDetails.ourSp,getOurTp(flipkartDetails,val,spm,mpItem),None,getLowestPossibleTp(flipkartDetails,val,spm,mpItem),None,getLowestPossibleSp(flipkartDetails,val,spm,mpItem),prefSellerTp)
|
| 857 |
temp.append(val)
|
848 |
temp.append(flipkartPricing)
|
| 858 |
secondLowestTp=0 if flipkartDetails.totalAvailableSeller==1 else getOtherTp(flipkartDetails,val,spm,False)
|
849 |
temp.append(mpItem)
|
| 859 |
prefSellerTp=0 if flipkartDetails.totalAvailableSeller < 2 else getOtherTp(flipkartDetails,val,spm,True)
|
850 |
cheapButNotPref.append(temp)
|
| 860 |
flipkartPricing = __FlipkartPricing(flipkartDetails.ourSp,getOurTp(flipkartDetails,val,spm,mpItem),None,getLowestPossibleTp(flipkartDetails,val,spm,mpItem),secondLowestTp,getLowestPossibleSp(flipkartDetails,val,spm,mpItem),prefSellerTp)
|
851 |
continue
|
| 861 |
temp.append(flipkartPricing)
|
852 |
|
| 862 |
temp.append(mpItem)
|
853 |
|
| 863 |
prefButNotCheap.append(temp)
|
854 |
lowestTp = getOtherTp(flipkartDetails,val,spm,False)
|
| 864 |
return
|
855 |
ourTp = getOurTp(flipkartDetails,val,spm,mpItem)
|
| 865 |
|
856 |
lowestPossibleTp = getLowestPossibleTp(flipkartDetails,val,spm,mpItem)
|
| 866 |
if (flipkartDetails.ourBuyTrend == 'NPrefCheap') and (flipkartDetails.rank==1):
|
857 |
lowestPossibleSp = getLowestPossibleSp(flipkartDetails,val,spm,mpItem)
|
| 867 |
temp=[]
|
858 |
prefSellerTp = getOtherTp(flipkartDetails,val,spm,True)
|
| 868 |
temp.append(flipkartDetails)
|
859 |
|
| 869 |
temp.append(val)
|
860 |
if (ourTp<lowestPossibleTp):
|
| 870 |
prefSellerTp=0 if flipkartDetails.totalAvailableSeller < 2 else getOtherTp(flipkartDetails,val,spm,True)
|
861 |
temp=[]
|
| 871 |
flipkartPricing = __FlipkartPricing(flipkartDetails.ourSp,getOurTp(flipkartDetails,val,spm,mpItem),None,getLowestPossibleTp(flipkartDetails,val,spm,mpItem),None,getLowestPossibleSp(flipkartDetails,val,spm,mpItem),prefSellerTp)
|
862 |
temp.append(flipkartDetails)
|
| 872 |
temp.append(flipkartPricing)
|
863 |
temp.append(val)
|
| 873 |
temp.append(mpItem)
|
864 |
flipkartPricing = __FlipkartPricing(ourSp,ourTp,lowestTp,lowestPossibleTp,None,None,None)
|
| 874 |
cheapButNotPref.append(temp)
|
865 |
temp.append(flipkartPricing)
|
| 875 |
return
|
866 |
negativeMargin.append(temp)
|
| 876 |
|
867 |
continue
|
| 877 |
|
868 |
|
| 878 |
lowestTp = getOtherTp(flipkartDetails,val,spm,False)
|
869 |
if (flipkartDetails.lowestSellerSp > lowestPossibleSp) and val.ourFlipkartInventory!=0:
|
| 879 |
ourTp = getOurTp(flipkartDetails,val,spm,mpItem)
|
870 |
type(val.ourFlipkartInventory)
|
| 880 |
lowestPossibleTp = getLowestPossibleTp(flipkartDetails,val,spm,mpItem)
|
871 |
temp=[]
|
| 881 |
lowestPossibleSp = getLowestPossibleSp(flipkartDetails,val,spm,mpItem)
|
872 |
temp.append(flipkartDetails)
|
| 882 |
prefSellerTp = getOtherTp(flipkartDetails,val,spm,True)
|
873 |
temp.append(val)
|
| 883 |
|
874 |
flipkartPricing = __FlipkartPricing(ourSp,ourTp,lowestTp,lowestPossibleTp,None,lowestPossibleSp,prefSellerTp)
|
| 884 |
if (ourTp<lowestPossibleTp):
|
875 |
temp.append(flipkartPricing)
|
| 885 |
temp=[]
|
876 |
temp.append(mpItem)
|
| 886 |
temp.append(flipkartDetails)
|
877 |
competitive.append(temp)
|
| 887 |
temp.append(val)
|
878 |
continue
|
| 888 |
flipkartPricing = __FlipkartPricing(ourSp,ourTp,lowestTp,lowestPossibleTp,None,None,None)
|
879 |
|
| 889 |
temp.append(flipkartPricing)
|
880 |
if (flipkartDetails.lowestSellerSp) > lowestPossibleSp and val.ourFlipkartInventory==0:
|
| 890 |
negativeMargin.append(temp)
|
881 |
temp=[]
|
| 891 |
return
|
882 |
temp.append(flipkartDetails)
|
| 892 |
|
883 |
temp.append(val)
|
| 893 |
if (flipkartDetails.lowestSellerSp > lowestPossibleSp) and val.ourFlipkartInventory!=0:
|
884 |
flipkartPricing = __FlipkartPricing(ourSp,ourTp,lowestTp,lowestPossibleTp,None,lowestPossibleSp,prefSellerTp)
|
| 894 |
type(val.ourFlipkartInventory)
|
885 |
temp.append(flipkartPricing)
|
| 895 |
temp=[]
|
886 |
temp.append(mpItem)
|
| 896 |
temp.append(flipkartDetails)
|
887 |
competitiveNoInventory.append(temp)
|
| 897 |
temp.append(val)
|
888 |
continue
|
| 898 |
flipkartPricing = __FlipkartPricing(ourSp,ourTp,lowestTp,lowestPossibleTp,None,lowestPossibleSp,prefSellerTp)
|
889 |
|
| 899 |
temp.append(flipkartPricing)
|
- |
|
| 900 |
temp.append(mpItem)
|
- |
|
| 901 |
competitive.append(temp)
|
- |
|
| 902 |
return
|
- |
|
| 903 |
|
- |
|
| 904 |
if (flipkartDetails.lowestSellerSp) > lowestPossibleSp and val.ourFlipkartInventory==0:
|
- |
|
| 905 |
temp=[]
|
890 |
temp=[]
|
| 906 |
temp.append(flipkartDetails)
|
891 |
temp.append(flipkartDetails)
|
| 907 |
temp.append(val)
|
892 |
temp.append(val)
|
| 908 |
flipkartPricing = __FlipkartPricing(ourSp,ourTp,lowestTp,lowestPossibleTp,None,lowestPossibleSp,prefSellerTp)
|
893 |
flipkartPricing = __FlipkartPricing(ourSp,ourTp,lowestTp,lowestPossibleTp,None,lowestPossibleSp,prefSellerTp)
|
| 909 |
temp.append(flipkartPricing)
|
894 |
temp.append(flipkartPricing)
|
| 910 |
temp.append(mpItem)
|
895 |
temp.append(mpItem)
|
| 911 |
competitiveNoInventory.append(temp)
|
896 |
cantCompete.append(temp)
|
| 912 |
return
|
- |
|
| 913 |
|
897 |
|
| 914 |
temp=[]
|
- |
|
| 915 |
temp.append(flipkartDetails)
|
- |
|
| 916 |
temp.append(val)
|
- |
|
| 917 |
flipkartPricing = __FlipkartPricing(ourSp,ourTp,lowestTp,lowestPossibleTp,None,lowestPossibleSp,prefSellerTp)
|
- |
|
| 918 |
temp.append(flipkartPricing)
|
- |
|
| 919 |
temp.append(mpItem)
|
- |
|
| 920 |
cantCompete.append(temp)
|
- |
|
| 921 |
|
- |
|
| 922 |
#return cantCompete, buyBoxItems, competitive, competitiveNoInventory, exceptionItems, negativeMargin, cheapButNotPref, prefButNotCheap
|
898 |
return cantCompete, buyBoxItems, competitive, competitiveNoInventory, exceptionItems, negativeMargin, cheapButNotPref, prefButNotCheap
|
| 923 |
|
899 |
|
| 924 |
def getOtherTp(flipkartDetails,val,spm,prefferedSeller):
|
900 |
def getOtherTp(flipkartDetails,val,spm,prefferedSeller):
|
| 925 |
if val.parent_category==10011 or val.parent_category==12001:
|
901 |
if val.parent_category==10011 or val.parent_category==12001:
|
| 926 |
commissionPercentage = spm.competitorCommissionAccessory
|
902 |
commissionPercentage = spm.competitorCommissionAccessory
|
| 927 |
else:
|
903 |
else:
|
| Line 1895... |
Line 1871... |
| 1895 |
smtpServer.sendmail(sender, recipients, msg.as_string())
|
1871 |
smtpServer.sendmail(sender, recipients, msg.as_string())
|
| 1896 |
print "Successfully sent email"
|
1872 |
print "Successfully sent email"
|
| 1897 |
except:
|
1873 |
except:
|
| 1898 |
print "Error: unable to send email."
|
1874 |
print "Error: unable to send email."
|
| 1899 |
|
1875 |
|
| - |
|
1876 |
def populateScrapingResults(val):
|
| - |
|
1877 |
global testcount
|
| 1900 |
def test(start,end):
|
1878 |
testcount+=1
|
| 1901 |
print "Start "+str(start)+" end"+str(end)
|
1879 |
print "*****testcount",testcount
|
| - |
|
1880 |
print val
|
| - |
|
1881 |
try:
|
| - |
|
1882 |
flipkartDetails = fetchDetails(val.fkSerialNumber,scraper)
|
| - |
|
1883 |
val.flipkartDetails = flipkartDetails
|
| - |
|
1884 |
except Exception as e:
|
| - |
|
1885 |
print "Unable to fetch details of",val.fkSerialNumber
|
| - |
|
1886 |
print e
|
| - |
|
1887 |
val.flipkartDetails = None
|
| - |
|
1888 |
return
|
| - |
|
1889 |
|
| - |
|
1890 |
try:
|
| - |
|
1891 |
request_url = "https://api.flipkart.net/sellers/skus/%s/listings"%(str(val.skuAtFlipkart))
|
| - |
|
1892 |
r = requests.get(request_url, auth=('m2z93iskuj81qiid', '0c7ab6a5-98c0-4cdc-8be3-72c591e0add4'))
|
| - |
|
1893 |
print "Inventory info",r.json()
|
| - |
|
1894 |
stock_count = int((r.json()['attributeValues'])['stock_count'])
|
| - |
|
1895 |
except:
|
| - |
|
1896 |
stock_count = 0
|
| - |
|
1897 |
|
| - |
|
1898 |
val.ourFlipkartInventory = stock_count
|
| 1902 |
|
1899 |
|
| 1903 |
def threadsToSpawn(runType,itemInfo,scraper,itemPopulated):
|
1900 |
def threadsToSpawn(runType,itemInfo,scraper,itemPopulated):
|
| 1904 |
global threads
|
- |
|
| 1905 |
if runType == RunType.FAVOURITE:
|
1901 |
if runType == RunType.FAVOURITE:
|
| 1906 |
startOffset = itemPopulated
|
1902 |
startOffset = itemPopulated
|
| 1907 |
endOffset = startOffset
|
1903 |
endOffset = startOffset
|
| 1908 |
while(len(threads)< 3 and endOffset<len(itemInfo)):
|
1904 |
while(len(threads)< 3 and endOffset<len(itemInfo)):
|
| 1909 |
endOffset = startOffset + 20
|
1905 |
endOffset = startOffset + 20
|
| 1910 |
if (endOffset >= len(itemInfo)):
|
1906 |
if (endOffset >= len(itemInfo)):
|
| 1911 |
endOffset = len(itemInfo)
|
1907 |
endOffset = len(itemInfo)
|
| 1912 |
t = threading.Thread(target=partial(decideCategory, itemInfo[startOffset:endOffset]))
|
1908 |
t = threading.Thread(target=partial(populateScrapingResults, itemInfo[startOffset:endOffset],scraper))
|
| 1913 |
#t = threading.Thread(target=partial(test, startOffset, endOffset))
|
1909 |
#t = threading.Thread(target=partial(test, startOffset, endOffset))
|
| 1914 |
threads.append(t)
|
1910 |
threads.append(t)
|
| 1915 |
startOffset = startOffset + 20
|
1911 |
startOffset = startOffset + 20
|
| 1916 |
[t.start() for t in threads]
|
1912 |
[t.start() for t in threads]
|
| 1917 |
[t.join() for t in threads]
|
1913 |
[t.join() for t in threads]
|
| 1918 |
threads = []
|
1914 |
threads = []
|
| 1919 |
return endOffset
|
1915 |
return endOffset
|
| 1920 |
else:
|
1916 |
else:
|
| 1921 |
count = 0
|
1917 |
count = 0
|
| 1922 |
pool = ThreadPool(10)
|
1918 |
pool = ThreadPool(5)
|
| 1923 |
startOffset = itemPopulated
|
1919 |
startOffset = itemPopulated
|
| 1924 |
endOffset = startOffset
|
1920 |
endOffset = startOffset
|
| 1925 |
while(count<10 and endOffset<len(itemInfo)):
|
1921 |
while(count<5 and endOffset<len(itemInfo)):
|
| - |
|
1922 |
print "inside while",testcount
|
| 1926 |
endOffset = startOffset + 50
|
1923 |
endOffset = startOffset + 50
|
| 1927 |
if (endOffset >= len(itemInfo)):
|
1924 |
if (endOffset >= len(itemInfo)):
|
| 1928 |
endOffset = len(itemInfo)
|
1925 |
endOffset = len(itemInfo)
|
| 1929 |
|
1926 |
|
| 1930 |
print itemInfo[startOffset:endOffset]
|
1927 |
print itemInfo[startOffset:endOffset]
|
| 1931 |
pool.map(decideCategory,itemInfo[startOffset:endOffset])
|
1928 |
pool.map(populateScrapingResults,itemInfo[startOffset:endOffset])
|
| 1932 |
#t = Process(target=decideCategory,args=(itemInfo[startOffset:endOffset], scraper))
|
1929 |
#t = Process(target=decideCategory,args=(itemInfo[startOffset:endOffset], scraper))
|
| 1933 |
#t = threading.Thread(target=partial(decideCategory, itemInfo[startOffset:endOffset], scraper))
|
1930 |
#t = threading.Thread(target=partial(decideCategory, itemInfo[startOffset:endOffset], scraper))
|
| 1934 |
#t = threading.Thread(target=partial(test, startOffset, endOffset))
|
1931 |
#t = threading.Thread(target=partial(test, startOffset, endOffset))
|
| 1935 |
#threads.append(t)
|
1932 |
#threads.append(t)
|
| 1936 |
startOffset = startOffset + 50
|
1933 |
startOffset = startOffset + 50
|
| Line 1938... |
Line 1935... |
| 1938 |
#[t.start() for t in threads]
|
1935 |
#[t.start() for t in threads]
|
| 1939 |
#[t.join() for t in threads]
|
1936 |
#[t.join() for t in threads]
|
| 1940 |
#threads = []
|
1937 |
#threads = []
|
| 1941 |
pool.close()
|
1938 |
pool.close()
|
| 1942 |
pool.join()
|
1939 |
pool.join()
|
| - |
|
1940 |
"returning offset******"
|
| - |
|
1941 |
time.sleep(5)
|
| 1943 |
return endOffset
|
1942 |
return endOffset
|
| 1944 |
|
1943 |
|
| 1945 |
|
1944 |
|
| 1946 |
def main():
|
1945 |
def main():
|
| 1947 |
parser = optparse.OptionParser()
|
1946 |
parser = optparse.OptionParser()
|
| Line 1956... |
Line 1955... |
| 1956 |
itemInfo= populateStuff(options.runType,timestamp)
|
1955 |
itemInfo= populateStuff(options.runType,timestamp)
|
| 1957 |
itemsPopulated = 0
|
1956 |
itemsPopulated = 0
|
| 1958 |
while (itemsPopulated<len(itemInfo)):
|
1957 |
while (itemsPopulated<len(itemInfo)):
|
| 1959 |
itemsPopulated = threadsToSpawn(options.runType,itemInfo,scraper,itemsPopulated)
|
1958 |
itemsPopulated = threadsToSpawn(options.runType,itemInfo,scraper,itemsPopulated)
|
| 1960 |
previousProcessingTimestamp = session.query(func.max(MarketPlaceHistory.timestamp)).filter(MarketPlaceHistory.source==OrderSource.FLIPKART).one()
|
1959 |
previousProcessingTimestamp = session.query(func.max(MarketPlaceHistory.timestamp)).filter(MarketPlaceHistory.source==OrderSource.FLIPKART).one()
|
| - |
|
1960 |
cantCompete, buyBoxItems, competitive, competitiveNoInventory, exceptionItems, negativeMargin, cheapButNotPref, prefButNotCheap = decideCategory(itemInfo)
|
| 1961 |
commitExceptionList(exceptionItems,timestamp)
|
1961 |
commitExceptionList(exceptionItems,timestamp)
|
| 1962 |
commitCantCompete(cantCompete,timestamp)
|
1962 |
commitCantCompete(cantCompete,timestamp)
|
| 1963 |
commitBuyBox(buyBoxItems,timestamp)
|
1963 |
commitBuyBox(buyBoxItems,timestamp)
|
| 1964 |
commitCompetitive(competitive,timestamp)
|
1964 |
commitCompetitive(competitive,timestamp)
|
| 1965 |
commitCompetitiveNoInventory(competitiveNoInventory,timestamp)
|
1965 |
commitCompetitiveNoInventory(competitiveNoInventory,timestamp)
|