| Line 22... |
Line 22... |
| 22 |
import smtplib
|
22 |
import smtplib
|
| 23 |
from email.mime.text import MIMEText
|
23 |
from email.mime.text import MIMEText
|
| 24 |
import email
|
24 |
import email
|
| 25 |
from email.mime.multipart import MIMEMultipart
|
25 |
from email.mime.multipart import MIMEMultipart
|
| 26 |
import email.encoders
|
26 |
import email.encoders
|
| 27 |
|
27 |
import urllib2
|
| - |
|
28 |
import mechanize
|
| - |
|
29 |
import cookielib
|
| 28 |
|
30 |
|
| 29 |
|
31 |
|
| 30 |
config_client = ConfigClient()
|
32 |
config_client = ConfigClient()
|
| 31 |
host = config_client.get_property('staging_hostname')
|
33 |
host = config_client.get_property('staging_hostname')
|
| - |
|
34 |
syncPrice=config_client.get_property('sync_price_on_marketplace')
|
| - |
|
35 |
|
| - |
|
36 |
|
| 32 |
DataService.initialize(db_hostname=host)
|
37 |
DataService.initialize(db_hostname=host)
|
| 33 |
import logging
|
38 |
import logging
|
| 34 |
lgr = logging.getLogger()
|
39 |
lgr = logging.getLogger()
|
| 35 |
lgr.setLevel(logging.DEBUG)
|
40 |
lgr.setLevel(logging.DEBUG)
|
| 36 |
fh = logging.FileHandler('snapdeal-history.log')
|
41 |
fh = logging.FileHandler('snapdeal-history.log')
|
| Line 92... |
Line 97... |
| 92 |
self.lowestPossibleTp = lowestPossibleTp
|
97 |
self.lowestPossibleTp = lowestPossibleTp
|
| 93 |
self.competitionBasis = competitionBasis
|
98 |
self.competitionBasis = competitionBasis
|
| 94 |
self.ourSp = ourSp
|
99 |
self.ourSp = ourSp
|
| 95 |
self.secondLowestSellerTp = secondLowestSellerTp
|
100 |
self.secondLowestSellerTp = secondLowestSellerTp
|
| 96 |
self.lowestPossibleSp = lowestPossibleSp
|
101 |
self.lowestPossibleSp = lowestPossibleSp
|
| - |
|
102 |
|
| - |
|
103 |
def getBrowserObject():
|
| - |
|
104 |
br = mechanize.Browser(factory=mechanize.RobustFactory())
|
| - |
|
105 |
cj = cookielib.LWPCookieJar()
|
| - |
|
106 |
br.set_cookiejar(cj)
|
| - |
|
107 |
br.set_handle_equiv(True)
|
| - |
|
108 |
br.set_handle_redirect(True)
|
| - |
|
109 |
br.set_handle_referer(True)
|
| - |
|
110 |
br.set_handle_robots(False)
|
| - |
|
111 |
br.set_debug_http(False)
|
| - |
|
112 |
br.set_debug_redirects(False)
|
| - |
|
113 |
br.set_debug_responses(False)
|
| - |
|
114 |
|
| - |
|
115 |
br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)
|
| - |
|
116 |
|
| - |
|
117 |
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'),
|
| - |
|
118 |
('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'),
|
| - |
|
119 |
('Accept-Encoding', 'gzip,deflate,sdch'),
|
| - |
|
120 |
('Accept-Language', 'en-US,en;q=0.8'),
|
| - |
|
121 |
('Accept-Charset', 'ISO-8859-1,utf-8;q=0.7,*;q=0.3')]
|
| - |
|
122 |
return br
|
| 97 |
|
123 |
|
| 98 |
def fetchItemsForAutoDecrease(time):
|
124 |
def fetchItemsForAutoDecrease(time):
|
| 99 |
successfulAutoDecrease = []
|
125 |
successfulAutoDecrease = []
|
| 100 |
autoDecrementItems = session.query(MarketPlaceHistory).join((MarketplaceItems,MarketPlaceHistory.item_id==MarketplaceItems.itemId))\
|
126 |
autoDecrementItems = session.query(MarketPlaceHistory).join((MarketplaceItems,MarketPlaceHistory.item_id==MarketplaceItems.itemId))\
|
| 101 |
.filter(MarketPlaceHistory.timestamp==time).filter(MarketPlaceHistory.source==OrderSource.SNAPDEAL).filter(MarketPlaceHistory.competitiveCategory==CompetitionCategory.COMPETITIVE)\
|
127 |
.filter(MarketPlaceHistory.timestamp==time).filter(MarketPlaceHistory.source==OrderSource.SNAPDEAL).filter(MarketPlaceHistory.competitiveCategory==CompetitionCategory.COMPETITIVE)\
|
| Line 1510... |
Line 1536... |
| 1510 |
mpItem.minimumPossibleTp = getNewLowestPossibleTp(mpItem,item.ourNlc,vatRate,sdItem.sellingPrice)
|
1536 |
mpItem.minimumPossibleTp = getNewLowestPossibleTp(mpItem,item.ourNlc,vatRate,sdItem.sellingPrice)
|
| 1511 |
mpItem.minimumPossibleSp = getNewLowestPossibleSp(mpItem,item.ourNlc,vatRate)
|
1537 |
mpItem.minimumPossibleSp = getNewLowestPossibleSp(mpItem,item.ourNlc,vatRate)
|
| 1512 |
markStatusForMarketplaceItems(sdItem,mpItem)
|
1538 |
markStatusForMarketplaceItems(sdItem,mpItem)
|
| 1513 |
session.commit()
|
1539 |
session.commit()
|
| 1514 |
|
1540 |
|
| - |
|
1541 |
def updatePricesOnSnapdeal(successfulAutoDecrease,successfulAutoIncrease):
|
| - |
|
1542 |
if not syncPrice:
|
| - |
|
1543 |
return
|
| - |
|
1544 |
url = 'http://support.shop2020.in:8080/Support/reports'
|
| - |
|
1545 |
br = getBrowserObject()
|
| - |
|
1546 |
br.open(url)
|
| - |
|
1547 |
br.open(url)
|
| - |
|
1548 |
br.select_form(nr=0)
|
| - |
|
1549 |
br.form['username'] = "amazon"
|
| - |
|
1550 |
br.form['password'] = "amazon"
|
| - |
|
1551 |
br.submit()
|
| - |
|
1552 |
for item in successfulAutoDecrease:
|
| - |
|
1553 |
sdItem = SnapdealItem.get_by(item_id=item.item_id)
|
| - |
|
1554 |
sellingPrice = str(math.ceil(item.proposedSellingPrice))
|
| - |
|
1555 |
supc = sdItem.supc
|
| - |
|
1556 |
br.open('http://support.shop2020.in:8080/Support/snapdeal-list!updateForAutoPricing?sellingPrice=%s&supc=%s&itemId=%s')%(sellingPrice,supc,str(item.item_id))
|
| - |
|
1557 |
for item in successfulAutoIncrease:
|
| - |
|
1558 |
sdItem = SnapdealItem.get_by(item_id=item.item_id)
|
| - |
|
1559 |
sellingPrice = str(math.ceil(item.ourSellingPrice+max(10,.01*item.ourSellingPrice)))
|
| - |
|
1560 |
supc = sdItem.supc
|
| - |
|
1561 |
updateUrl = 'http://support.shop2020.in:8080/Support/snapdeal-list!updateForAutoPricing?sellingPrice=%s&supc=%s&itemId=%s'%(sellingPrice,supc,str(item.item_id))
|
| - |
|
1562 |
br.open(updateUrl)
|
| - |
|
1563 |
|
| - |
|
1564 |
|
| - |
|
1565 |
|
| 1515 |
def addHistory(item):
|
1566 |
def addHistory(item):
|
| 1516 |
itemHistory = MarketPlaceUpdateHistory()
|
1567 |
itemHistory = MarketPlaceUpdateHistory()
|
| 1517 |
itemHistory.item_id = item.item_id
|
1568 |
itemHistory.item_id = item.item_id
|
| 1518 |
itemHistory.source = OrderSource.SNAPDEAL
|
1569 |
itemHistory.source = OrderSource.SNAPDEAL
|
| 1519 |
itemHistory.exceptionPrice = item.exceptionPrice
|
1570 |
itemHistory.exceptionPrice = item.exceptionPrice
|
| Line 1722... |
Line 1773... |
| 1722 |
else:
|
1773 |
else:
|
| 1723 |
writeReport(cantCompete, buyBoxItems, competitive, competitiveNoInventory, exceptionList, negativeMargin, None, None, timestamp, options.runType)
|
1774 |
writeReport(cantCompete, buyBoxItems, competitive, competitiveNoInventory, exceptionList, negativeMargin, None, None, timestamp, options.runType)
|
| 1724 |
commitPricing(successfulAutoDecrease,successfulAutoIncrease,timestamp)
|
1775 |
commitPricing(successfulAutoDecrease,successfulAutoIncrease,timestamp)
|
| 1725 |
sendAutoPricingMail(successfulAutoDecrease,successfulAutoIncrease)
|
1776 |
sendAutoPricingMail(successfulAutoDecrease,successfulAutoIncrease)
|
| 1726 |
processLostBuyBoxItems(previousProcessingTimestamp[0],timestamp)
|
1777 |
processLostBuyBoxItems(previousProcessingTimestamp[0],timestamp)
|
| - |
|
1778 |
updatePricesOnSnapdeal(successfulAutoDecrease,successfulAutoIncrease)
|
| 1727 |
|
1779 |
|
| 1728 |
if __name__ == '__main__':
|
1780 |
if __name__ == '__main__':
|
| 1729 |
main()
|
1781 |
main()
|
| 1730 |
|
1782 |
|