| Line 33... |
Line 33... |
| 33 |
import email.encoders
|
33 |
import email.encoders
|
| 34 |
import cookielib
|
34 |
import cookielib
|
| 35 |
from multiprocessing import Pool
|
35 |
from multiprocessing import Pool
|
| 36 |
from multiprocessing.dummy import Pool as ThreadPool
|
36 |
from multiprocessing.dummy import Pool as ThreadPool
|
| 37 |
import gc
|
37 |
import gc
|
| - |
|
38 |
import mechanize
|
| 38 |
|
39 |
|
| 39 |
config_client = ConfigClient()
|
40 |
config_client = ConfigClient()
|
| 40 |
host = config_client.get_property('staging_hostname')
|
41 |
host = config_client.get_property('staging_hostname')
|
| 41 |
syncPrice=config_client.get_property('sync_price_on_marketplace')
|
42 |
syncPrice=config_client.get_property('sync_price_on_marketplace')
|
| 42 |
|
43 |
|
| Line 118... |
Line 119... |
| 118 |
self.ourSp = ourSp
|
119 |
self.ourSp = ourSp
|
| 119 |
self.secondLowestSellerTp = secondLowestSellerTp
|
120 |
self.secondLowestSellerTp = secondLowestSellerTp
|
| 120 |
self.lowestPossibleSp = lowestPossibleSp
|
121 |
self.lowestPossibleSp = lowestPossibleSp
|
| 121 |
self.prefSellerTp = prefSellerTp
|
122 |
self.prefSellerTp = prefSellerTp
|
| 122 |
|
123 |
|
| - |
|
124 |
def getBrowserObject():
|
| - |
|
125 |
br = mechanize.Browser(factory=mechanize.RobustFactory())
|
| - |
|
126 |
cj = cookielib.LWPCookieJar()
|
| - |
|
127 |
br.set_cookiejar(cj)
|
| - |
|
128 |
br.set_handle_equiv(True)
|
| - |
|
129 |
br.set_handle_redirect(True)
|
| - |
|
130 |
br.set_handle_referer(True)
|
| - |
|
131 |
br.set_handle_robots(False)
|
| - |
|
132 |
br.set_debug_http(False)
|
| - |
|
133 |
br.set_debug_redirects(False)
|
| - |
|
134 |
br.set_debug_responses(False)
|
| - |
|
135 |
|
| - |
|
136 |
br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)
|
| - |
|
137 |
|
| - |
|
138 |
br.addheaders = [('User-agent','Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11'),
|
| - |
|
139 |
('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'),
|
| - |
|
140 |
('Accept-Encoding', 'gzip,deflate,sdch'),
|
| - |
|
141 |
('Accept-Language', 'en-US,en;q=0.8'),
|
| - |
|
142 |
('Accept-Charset', 'ISO-8859-1,utf-8;q=0.7,*;q=0.3')]
|
| - |
|
143 |
return br
|
| - |
|
144 |
|
| 123 |
def markReasonForMpItem(mpHistory,reason,decision):
|
145 |
def markReasonForMpItem(mpHistory,reason,decision):
|
| 124 |
mpHistory.decision = decision
|
146 |
mpHistory.decision = decision
|
| 125 |
mpHistory.reason = reason
|
147 |
mpHistory.reason = reason
|
| 126 |
|
148 |
|
| 127 |
def fetchItemsForAutoDecrease(time):
|
149 |
def fetchItemsForAutoDecrease(time):
|
| Line 2805... |
Line 2827... |
| 2805 |
smtpServer.sendmail(sender, recipients, msg.as_string())
|
2827 |
smtpServer.sendmail(sender, recipients, msg.as_string())
|
| 2806 |
print "Successfully sent email"
|
2828 |
print "Successfully sent email"
|
| 2807 |
except:
|
2829 |
except:
|
| 2808 |
print "Error: unable to send email."
|
2830 |
print "Error: unable to send email."
|
| 2809 |
|
2831 |
|
| - |
|
2832 |
def commitPricing(successfulAutoDecrease,successfulAutoIncrease,timestamp):
|
| - |
|
2833 |
catalog_client = CatalogClient().get_client()
|
| - |
|
2834 |
inventory_client = InventoryClient().get_client()
|
| - |
|
2835 |
for item in successfulAutoDecrease:
|
| - |
|
2836 |
it = Item.query.filter_by(id=item.item_id).one()
|
| - |
|
2837 |
mpItem = MarketplaceItems.get_by(itemId=item.item_id,source=OrderSource.FLIPKART)
|
| 2810 |
|
- |
|
| - |
|
2838 |
fkItem = FlipkartItem.get_by(item_id=item.item_id)
|
| - |
|
2839 |
warehouse = inventory_client.getWarehouse(fkItem.warehouseId)
|
| - |
|
2840 |
vatRate = catalog_client.getVatPercentageForItem(item.item_id, warehouse.stateId, item.proposedSellingPrice)
|
| - |
|
2841 |
mpItem.currentTp = getNewOurTp(mpItem,item.proposedSellingPrice)
|
| - |
|
2842 |
mpItem.currentSp = math.ceil(item.proposedSellingPrice)
|
| - |
|
2843 |
fkItem.commissionValue = round((mpItem.commission/100)*(mpItem.currentSp),2)
|
| - |
|
2844 |
fkItem.serviceTaxValue = round((mpItem.serviceTax/100)*(fkItem.commissionValue+mpItem.courierCost),2)
|
| - |
|
2845 |
fkItem.updatedOn = timestamp
|
| - |
|
2846 |
fkItem.priceUpdatedBy = 'SYSTEM'
|
| - |
|
2847 |
mpItem.minimumPossibleTp = getNewLowestPossibleTp(mpItem,item.ourNlc,vatRate,item.proposedSellingPrice)
|
| - |
|
2848 |
mpItem.minimumPossibleSp = getNewLowestPossibleSp(mpItem,item.ourNlc,vatRate)
|
| - |
|
2849 |
addHistory(fkItem,mpItem)
|
| - |
|
2850 |
markStatusForMarketplaceItems(fkItem,mpItem)
|
| - |
|
2851 |
session.commit()
|
| - |
|
2852 |
for item in successfulAutoIncrease:
|
| - |
|
2853 |
it = Item.query.filter_by(id=item.item_id).one()
|
| - |
|
2854 |
mpItem = MarketplaceItems.get_by(itemId=item.item_id,source=OrderSource.FLIPKART)
|
| - |
|
2855 |
fkItem = FlipkartItem.get_by(item_id=item.item_id)
|
| - |
|
2856 |
addHistory(fkItem,mpItem)
|
| - |
|
2857 |
warehouse = inventory_client.getWarehouse(fkItem.warehouseId)
|
| - |
|
2858 |
vatRate = catalog_client.getVatPercentageForItem(item.item_id, warehouse.stateId, item.proposedSellingPrice)
|
| - |
|
2859 |
mpItem.currentTp = getNewOurTp(mpItem,item.ourSellingPrice+max(10,.01*item.ourSellingPrice))
|
| - |
|
2860 |
mpItem.currentSp = math.ceil(item.ourSellingPrice+max(10,.01*item.ourSellingPrice))
|
| - |
|
2861 |
fkItem.commissionValue = round((mpItem.commission/100)*(mpItem.currentSp),2)
|
| - |
|
2862 |
fkItem.serviceTaxValue = round((mpItem.serviceTax/100)*(fkItem.commissionValue+mpItem.courierCost),2)
|
| - |
|
2863 |
fkItem.updatedOn = timestamp
|
| - |
|
2864 |
fkItem.priceUpdatedBy = 'SYSTEM'
|
| - |
|
2865 |
mpItem.minimumPossibleTp = getNewLowestPossibleTp(mpItem,item.ourNlc,vatRate,mpItem.currentSp)
|
| - |
|
2866 |
mpItem.minimumPossibleSp = getNewLowestPossibleSp(mpItem,item.ourNlc,vatRate)
|
| - |
|
2867 |
addHistory(fkItem,mpItem)
|
| - |
|
2868 |
markStatusForMarketplaceItems(fkItem,mpItem)
|
| - |
|
2869 |
session.commit()
|
| 2811 |
|
2870 |
|
| - |
|
2871 |
def addHistory(fkItem,mpItem):
|
| - |
|
2872 |
itemHistory = MarketPlaceUpdateHistory()
|
| - |
|
2873 |
itemHistory.item_id = fkItem.item_id
|
| - |
|
2874 |
itemHistory.source = OrderSource.FLIPKART
|
| - |
|
2875 |
itemHistory.exceptionPrice = fkItem.exceptionPrice
|
| - |
|
2876 |
itemHistory.warehouseId = fkItem.warehouseId
|
| - |
|
2877 |
itemHistory.isListedOnSource = fkItem.isListedOnFlipkart
|
| - |
|
2878 |
itemHistory.transferPrice = mpItem.currentTp
|
| - |
|
2879 |
itemHistory.sellingPrice = mpItem.currentSp
|
| - |
|
2880 |
itemHistory.courierCost = mpItem.courierCost
|
| - |
|
2881 |
itemHistory.commission = fkItem.commissionValue
|
| - |
|
2882 |
itemHistory.serviceTax = fkItem.serviceTaxValue
|
| - |
|
2883 |
itemHistory.suppressPriceFeed = fkItem.suppressPriceFeed
|
| - |
|
2884 |
itemHistory.suppressInventoryFeed = fkItem.suppressInventoryFeed
|
| - |
|
2885 |
itemHistory.updatedOn = fkItem.updatedOn
|
| - |
|
2886 |
itemHistory.maxNlc = fkItem.maxNlc
|
| - |
|
2887 |
itemHistory.skuAtSource = fkItem.skuAtFlipkart
|
| - |
|
2888 |
itemHistory.marketPlaceSerialNumber = fkItem.flipkartSerialNumber
|
| - |
|
2889 |
itemHistory.priceUpdatedBy = fkItem.updatedBy
|
| - |
|
2890 |
itemHistory.courierCostMarketplace = mpItem.courierCostMarketplace
|
| - |
|
2891 |
|
| - |
|
2892 |
def markStatusForMarketplaceItems(fkItem,mpItem):
|
| - |
|
2893 |
markUpdatedItem = MarketPlaceItemPrice.query.filter(MarketPlaceItemPrice.item_id==fkItem.item_id).filter(MarketPlaceItemPrice.source==mpItem.source).first()
|
| - |
|
2894 |
if markUpdatedItem is None:
|
| - |
|
2895 |
marketPlaceItemPrice = MarketPlaceItemPrice()
|
| - |
|
2896 |
marketPlaceItemPrice.item_id = fkItem.item_id
|
| - |
|
2897 |
marketPlaceItemPrice.source = mpItem.source
|
| - |
|
2898 |
marketPlaceItemPrice.lastUpdatedOn = fkItem.updatedOn
|
| - |
|
2899 |
marketPlaceItemPrice.sellingPrice = mpItem.currentSp
|
| - |
|
2900 |
marketPlaceItemPrice.suppressPriceFeed = fkItem.suppressPriceFeed
|
| - |
|
2901 |
marketPlaceItemPrice.isListedOnSource = fkItem.isListedOnFlipkart
|
| - |
|
2902 |
else:
|
| - |
|
2903 |
if (markUpdatedItem.sellingPrice!=mpItem.currentSp or markUpdatedItem.suppressPriceFeed!=fkItem.suppressPriceFeed or markUpdatedItem.isListedOnSource!=fkItem.isListedOnFlipkart):
|
| - |
|
2904 |
markUpdatedItem.lastUpdatedOn = fkItem.updatedOn
|
| - |
|
2905 |
markUpdatedItem.sellingPrice = mpItem.currentSp
|
| - |
|
2906 |
markUpdatedItem.suppressPriceFeed = fkItem.suppressPriceFeed
|
| - |
|
2907 |
markUpdatedItem.isListedOnSource = fkItem.isListedOnFlipkart
|
| - |
|
2908 |
|
| 2812 |
|
2909 |
|
| - |
|
2910 |
|
| - |
|
2911 |
def updatePriceOnFlipkart(successfulAutoDecrease,successfulAutoIncrease):
|
| - |
|
2912 |
if syncPrice=='false':
|
| - |
|
2913 |
return
|
| - |
|
2914 |
url = 'http://support.shop2020.in:8080/Support/reports'
|
| - |
|
2915 |
br = getBrowserObject()
|
| - |
|
2916 |
br.open(url)
|
| - |
|
2917 |
br.select_form(nr=0)
|
| - |
|
2918 |
br.form['username'] = "manoj"
|
| - |
|
2919 |
br.form['password'] = "man0j"
|
| - |
|
2920 |
br.submit()
|
| - |
|
2921 |
for item in successfulAutoDecrease:
|
| - |
|
2922 |
fkItem = FlipkartItem.get_by(item_id=item.item_id)
|
| - |
|
2923 |
sellingPrice = str(math.ceil(item.proposedSellingPrice))
|
| - |
|
2924 |
flipkartSku = fkItem.skuAtFlipkart
|
| - |
|
2925 |
if fkItem.isListedOnFlipkart:
|
| - |
|
2926 |
updateUrl = 'http://support.shop2020.in:8080/Support/flipkart-list!updateForAutoPricing?sellingPrice=%s&fkItemCode=%s&itemId=%s'%(sellingPrice,flipkartSku,str(item.item_id))
|
| - |
|
2927 |
br.open(updateUrl)
|
| - |
|
2928 |
for item in successfulAutoIncrease:
|
| - |
|
2929 |
fkItem = FlipkartItem.get_by(item_id=item.item_id)
|
| - |
|
2930 |
sellingPrice = str(math.ceil(item.ourSellingPrice+max(10,.01*item.ourSellingPrice)))
|
| - |
|
2931 |
flipkartSku = fkItem.skuAtFlipkart
|
| - |
|
2932 |
if fkItem.isListedOnFlipkart:
|
| - |
|
2933 |
updateUrl = 'http://support.shop2020.in:8080/Support/flipkart-list!updateForAutoPricing?sellingPrice=%s&fkItemCode=%s&itemId=%s'%(sellingPrice,flipkartSku,str(item.item_id))
|
| - |
|
2934 |
br.open(updateUrl)
|
| 2813 |
|
2935 |
|
| 2814 |
def main():
|
2936 |
def main():
|
| 2815 |
parser = optparse.OptionParser()
|
2937 |
parser = optparse.OptionParser()
|
| 2816 |
parser.add_option("-t", "--type", dest="runType",
|
2938 |
parser.add_option("-t", "--type", dest="runType",
|
| 2817 |
default="FULL", type="string",
|
2939 |
default="FULL", type="string",
|
| Line 2846... |
Line 2968... |
| 2846 |
previousAutoFav, nowAutoFav = markAutoFavourite()
|
2968 |
previousAutoFav, nowAutoFav = markAutoFavourite()
|
| 2847 |
if options.runType =='FULL':
|
2969 |
if options.runType =='FULL':
|
| 2848 |
write_report(previousAutoFav,nowAutoFav,timestamp,options.runType)
|
2970 |
write_report(previousAutoFav,nowAutoFav,timestamp,options.runType)
|
| 2849 |
else:
|
2971 |
else:
|
| 2850 |
write_report(None,None,timestamp,options.runType)
|
2972 |
write_report(None,None,timestamp,options.runType)
|
| - |
|
2973 |
commitPricing(successfulAutoDecrease,successfulAutoIncrease)
|
| 2851 |
sendAutoPricingMail(successfulAutoDecrease,successfulAutoIncrease)
|
2974 |
sendAutoPricingMail(successfulAutoDecrease,successfulAutoIncrease)
|
| - |
|
2975 |
updatePriceOnFlipkart(successfulAutoDecrease,successfulAutoIncrease)
|
| 2852 |
if previousProcessingTimestamp[0] is not None:
|
2976 |
if previousProcessingTimestamp[0] is not None:
|
| 2853 |
processLostBuyBoxItems(previousProcessingTimestamp[0],timestamp)
|
2977 |
processLostBuyBoxItems(previousProcessingTimestamp[0],timestamp)
|
| 2854 |
if options.runType=='FULL':
|
2978 |
if options.runType=='FULL':
|
| 2855 |
cheapButNotPrefAlert(timestamp)
|
2979 |
cheapButNotPrefAlert(timestamp)
|
| 2856 |
sendPricingMismatch(timestamp)
|
2980 |
sendPricingMismatch(timestamp)
|