| Line 1... |
Line 1... |
| 1 |
from elixir import *
|
1 |
from elixir import *
|
| 2 |
from shop2020.config.client.ConfigClient import ConfigClient
|
2 |
from shop2020.config.client.ConfigClient import ConfigClient
|
| 3 |
from shop2020.model.v1.catalog.impl import DataService
|
3 |
from shop2020.model.v1.catalog.impl import DataService
|
| 4 |
from shop2020.model.v1.catalog.impl.DataService import SnapdealItem, MarketplaceItems, Item
|
4 |
from shop2020.model.v1.catalog.impl.DataService import SnapdealItem, MarketplaceItems, Item, Category
|
| 5 |
from shop2020.thriftpy.model.v1.order.ttypes import OrderSource
|
5 |
from shop2020.thriftpy.model.v1.order.ttypes import OrderSource
|
| 6 |
import mechanize
|
6 |
import mechanize
|
| 7 |
import sys
|
7 |
import sys
|
| 8 |
import cookielib
|
8 |
import cookielib
|
| 9 |
from time import sleep
|
9 |
from time import sleep
|
| 10 |
import json
|
10 |
import json
|
| 11 |
import smtplib
|
11 |
import smtplib
|
| - |
|
12 |
import xlwt
|
| 12 |
from datetime import datetime
|
13 |
from datetime import datetime
|
| 13 |
from shop2020.utils import EmailAttachmentSender
|
14 |
from shop2020.utils import EmailAttachmentSender
|
| 14 |
from shop2020.utils.EmailAttachmentSender import get_attachment_part
|
15 |
from shop2020.utils.EmailAttachmentSender import get_attachment_part
|
| 15 |
from email.mime.text import MIMEText
|
16 |
from email.mime.text import MIMEText
|
| 16 |
import email
|
17 |
import email
|
| Line 20... |
Line 21... |
| 20 |
config_client = ConfigClient()
|
21 |
config_client = ConfigClient()
|
| 21 |
host = config_client.get_property('staging_hostname')
|
22 |
host = config_client.get_property('staging_hostname')
|
| 22 |
DataService.initialize(db_hostname=host)
|
23 |
DataService.initialize(db_hostname=host)
|
| 23 |
|
24 |
|
| 24 |
class __SnapdealInfo:
|
25 |
class __SnapdealInfo:
|
| 25 |
def __init__(self, sellingPrice, weight, transferPrice, commission, commissionPercentage, courierCost, sellingPriceSnapdeal, transferPriceSnapdeal, fixedMargin, fixedMarginPercentage, collectionCharges, logisticCostSnapdeal, weightSnapdeal, supc, itemId):
|
26 |
def __init__(self, sellingPrice, weight, transferPrice, commission, commissionPercentage, courierCost, sellingPriceSnapdeal, transferPriceSnapdeal, fixedMargin, \
|
| - |
|
27 |
fixedMarginPercentage, collectionCharges, logisticCostSnapdeal, weightSnapdeal, supc, itemId, parentCategory, productGroup ,brand, modelName, modelNumber, \
|
| - |
|
28 |
color):
|
| 26 |
|
29 |
|
| 27 |
self.sellingPrice = sellingPrice
|
30 |
self.sellingPrice = sellingPrice
|
| 28 |
self.weight = weight
|
31 |
self.weight = weight
|
| 29 |
self.transferPrice = transferPrice
|
32 |
self.transferPrice = transferPrice
|
| 30 |
self.commission = commission
|
33 |
self.commission = commission
|
| Line 37... |
Line 40... |
| 37 |
self.collectionCharges = collectionCharges
|
40 |
self.collectionCharges = collectionCharges
|
| 38 |
self.logisticCostSnapdeal = logisticCostSnapdeal
|
41 |
self.logisticCostSnapdeal = logisticCostSnapdeal
|
| 39 |
self.weightSnapdeal = weightSnapdeal
|
42 |
self.weightSnapdeal = weightSnapdeal
|
| 40 |
self.supc = supc
|
43 |
self.supc = supc
|
| 41 |
self.itemId = itemId
|
44 |
self.itemId = itemId
|
| - |
|
45 |
self.parentCategory = parentCategory
|
| - |
|
46 |
self.productGroup = productGroup
|
| - |
|
47 |
self.brand = brand
|
| - |
|
48 |
self.modelName = modelName
|
| - |
|
49 |
self.modelNumber = modelNumber
|
| - |
|
50 |
self.color = color
|
| - |
|
51 |
|
| 42 |
|
52 |
|
| 43 |
def getBrowserObject():
|
53 |
def getBrowserObject():
|
| 44 |
br = mechanize.Browser(factory=mechanize.RobustFactory())
|
54 |
br = mechanize.Browser(factory=mechanize.RobustFactory())
|
| 45 |
cj = cookielib.LWPCookieJar()
|
55 |
cj = cookielib.LWPCookieJar()
|
| 46 |
br.set_cookiejar(cj)
|
56 |
br.set_cookiejar(cj)
|
| Line 73... |
Line 83... |
| 73 |
return br
|
83 |
return br
|
| 74 |
|
84 |
|
| 75 |
def populateStuff(br):
|
85 |
def populateStuff(br):
|
| 76 |
exceptionList = []
|
86 |
exceptionList = []
|
| 77 |
fetchedItems = []
|
87 |
fetchedItems = []
|
| 78 |
items = session.query(SnapdealItem,MarketplaceItems).join((MarketplaceItems,SnapdealItem.item_id==MarketplaceItems.itemId)).filter(MarketplaceItems.source==OrderSource.SNAPDEAL).all()
|
88 |
items = session.query(SnapdealItem,MarketplaceItems,Item).join((MarketplaceItems,SnapdealItem.item_id==MarketplaceItems.itemId)).join((Item,SnapdealItem.item_id==Item.id)).filter(MarketplaceItems.source==OrderSource.SNAPDEAL).all()
|
| 79 |
for item in items:
|
89 |
for item in items:
|
| 80 |
snapdealItem = item[0]
|
90 |
snapdealItem = item[0]
|
| 81 |
marketplaceItem = item[1]
|
91 |
marketplaceItem = item[1]
|
| - |
|
92 |
ds_item = item[2]
|
| - |
|
93 |
category = Category.query.filter_by(id=ds_item.category).one()
|
| - |
|
94 |
parent_category = Category.query.filter_by(id=category.parent_category_id).first()
|
| 82 |
try:
|
95 |
try:
|
| 83 |
print "Inside try for fetch data"
|
96 |
print "Inside try for fetch data"
|
| 84 |
snapdealInfo = fetchData(br,snapdealItem.supc)
|
97 |
snapdealInfo = fetchData(br,snapdealItem.supc)
|
| 85 |
except Exception as e:
|
98 |
except Exception as e:
|
| 86 |
exceptionList.append(item)
|
99 |
exceptionList.append(item)
|
| Line 90... |
Line 103... |
| 90 |
snapdealInfo.courierCost = snapdealItem.courierCost
|
103 |
snapdealInfo.courierCost = snapdealItem.courierCost
|
| 91 |
snapdealInfo.transferPrice = snapdealItem.transferPrice
|
104 |
snapdealInfo.transferPrice = snapdealItem.transferPrice
|
| 92 |
snapdealInfo.commissionPercentage = marketplaceItem.commission
|
105 |
snapdealInfo.commissionPercentage = marketplaceItem.commission
|
| 93 |
snapdealInfo.commission = snapdealItem.commission
|
106 |
snapdealInfo.commission = snapdealItem.commission
|
| 94 |
snapdealInfo.itemId = snapdealItem.item_id
|
107 |
snapdealInfo.itemId = snapdealItem.item_id
|
| - |
|
108 |
snapdealInfo.parentCategory = parent_category.display_name
|
| - |
|
109 |
snapdealInfo.productGroup = ds_item.product_group
|
| - |
|
110 |
snapdealInfo.brand = ds_item.brand
|
| - |
|
111 |
snapdealInfo.modelName = ds_item.model_name
|
| - |
|
112 |
snapdealInfo.modelNumber = ds_item.model_number
|
| - |
|
113 |
snapdealInfo.color = ds_item.color
|
| - |
|
114 |
snapdealInfo.weight = ds_item.weight
|
| 95 |
fetchedItems.append(snapdealInfo)
|
115 |
fetchedItems.append(snapdealInfo)
|
| 96 |
return exceptionList, fetchedItems
|
116 |
return exceptionList, fetchedItems
|
| 97 |
|
117 |
|
| 98 |
def fetchData(br,supc):
|
118 |
def fetchData(br,supc):
|
| 99 |
url="http://seller.snapdeal.com/pricing/search?searchType=SUPC&searchValue=%s&gridType=normal&_search=false&nd=1396007375971&rows=30&page=1&sidx=&sord=asc"%(supc)
|
119 |
url="http://seller.snapdeal.com/pricing/search?searchType=SUPC&searchValue=%s&gridType=normal&_search=false&nd=1396007375971&rows=30&page=1&sidx=&sord=asc"%(supc)
|
| Line 101... |
Line 121... |
| 101 |
response = br.open(url)
|
121 |
response = br.open(url)
|
| 102 |
dataform = str(response.read()).strip("'<>() ").replace('\'', '\"')
|
122 |
dataform = str(response.read()).strip("'<>() ").replace('\'', '\"')
|
| 103 |
struct = json.loads(dataform)
|
123 |
struct = json.loads(dataform)
|
| 104 |
sdObj = struct['rows'][0]
|
124 |
sdObj = struct['rows'][0]
|
| 105 |
print sdObj
|
125 |
print sdObj
|
| 106 |
snapdealInfo = __SnapdealInfo(None,None,None,None,None,None,sdObj['sellingPrice'],sdObj['netSellerPayable'],sdObj['fixedMarginAmount'],sdObj['fixedMarginPercent'],sdObj['collectionCharges'],sdObj['logisticCost'],sdObj['deadWeight'],supc,None)
|
126 |
snapdealInfo = __SnapdealInfo(None,None,None,None,None,None,sdObj['sellingPrice'],sdObj['netSellerPayable'],sdObj['fixedMarginAmount'],sdObj['fixedMarginPercent'],sdObj['collectionCharges'],sdObj['logisticCost'],sdObj['deadWeight'],supc,None, \
|
| - |
|
127 |
None, None, None, None, None, None)
|
| 107 |
return snapdealInfo
|
128 |
return snapdealInfo
|
| 108 |
|
129 |
|
| 109 |
def filterData(fetchedItems):
|
130 |
def filterData(fetchedItems):
|
| - |
|
131 |
filterList = []
|
| 110 |
for data in fetchedItems:
|
132 |
for data in fetchedItems:
|
| - |
|
133 |
print data.itemId
|
| - |
|
134 |
print data.transferPrice
|
| - |
|
135 |
print data.transferPriceSnapdeal
|
| 111 |
if ( data.transferPrice - data.transferPriceSnapdeal >= -3 ) and (data.transferPrice - data.transferPriceSnapdeal <= 3):
|
136 |
if ( data.transferPrice - data.transferPriceSnapdeal >= -3 ) and (data.transferPrice - data.transferPriceSnapdeal <= 3):
|
| 112 |
print "Removing itemId ",data.itemId
|
137 |
continue
|
| 113 |
fetchedItems.remove(data)
|
138 |
filterList.append(data)
|
| 114 |
return fetchedItems
|
139 |
return filterList
|
| 115 |
|
140 |
|
| 116 |
def sendMail(filteredData,exceptionList):
|
141 |
def sendMail(filteredData,exceptionList):
|
| 117 |
xstr = lambda s: s or ""
|
142 |
xstr = lambda s: s or ""
|
| 118 |
message="""<html>
|
143 |
message="""<html>
|
| 119 |
<body>
|
144 |
<body>
|
| Line 136... |
Line 161... |
| 136 |
<th>Snapdeal Courier Charges</th>
|
161 |
<th>Snapdeal Courier Charges</th>
|
| 137 |
</tr></thead>
|
162 |
</tr></thead>
|
| 138 |
<tbody>"""
|
163 |
<tbody>"""
|
| 139 |
for data in filteredData:
|
164 |
for data in filteredData:
|
| 140 |
if data.transferPriceSnapdeal < data.transferPrice:
|
165 |
if data.transferPriceSnapdeal < data.transferPrice:
|
| 141 |
it = Item.query.filter_by(id=data.itemId).one()
|
- |
|
| 142 |
message+="""<tr>
|
166 |
message+="""<tr>
|
| 143 |
<td style="text-align:center">"""+str(data.itemId)+"""</td>
|
167 |
<td style="text-align:center">"""+str(data.itemId)+"""</td>
|
| 144 |
<td style="text-align:center">"""+xstr(it.brand)+" "+xstr(it.model_name)+" "+xstr(it.model_number)+" "+xstr(it.color)+"""</td>
|
168 |
<td style="text-align:center">"""+xstr(data.brand)+" "+xstr(data.modelName)+" "+xstr(data.modelNumber)+" "+xstr(data.color)+"""</td>
|
| 145 |
<td style="text-align:center">"""+str(data.sellingPrice)+"""</td>
|
169 |
<td style="text-align:center">"""+str(data.sellingPrice)+"""</td>
|
| 146 |
<td style="text-align:center">"""+str(data.sellingPriceSnapdeal)+"""</td>
|
170 |
<td style="text-align:center">"""+str(data.sellingPriceSnapdeal)+"""</td>
|
| 147 |
<td style="text-align:center">"""+str(data.transferPrice)+"""</td>
|
171 |
<td style="text-align:center">"""+str(data.transferPrice)+"""</td>
|
| 148 |
<td style="text-align:center">"""+str(data.transferPriceSnapdeal)+"""</td>
|
172 |
<td style="text-align:center">"""+str(data.transferPriceSnapdeal)+"""</td>
|
| 149 |
<td style="text-align:center">"""+str(data.commission*1.1236)+"""</td>
|
173 |
<td style="text-align:center">"""+str(round(data.commission*1.1236,2))+"""</td>
|
| 150 |
<td style="text-align:center">"""+str(round(float(data.fixedMargin)+float(data.collectionCharges),2))+"""</td>
|
174 |
<td style="text-align:center">"""+str(round(float(data.fixedMargin)+float(data.collectionCharges),2))+"""</td>
|
| 151 |
<td style="text-align:center">"""+str(data.commissionPercentage)+"%"+"""</td>
|
175 |
<td style="text-align:center">"""+str(data.commissionPercentage)+"%"+"""</td>
|
| 152 |
<td style="text-align:center">"""+str(round(float(data.fixedMarginPercentage)/1.1236,2))+"%"+"""</td>
|
176 |
<td style="text-align:center">"""+str(round(float(data.fixedMarginPercentage)/1.1236,2))+"%"+"""</td>
|
| 153 |
<td style="text-align:center">"""+str(it.weight*100)+" gms"+"""</td>
|
177 |
<td style="text-align:center">"""+str(data.weight*1000)+" gms"+"""</td>
|
| 154 |
<td style="text-align:center">"""+str(data.weightSnapdeal)+" gms"+"""</td>
|
178 |
<td style="text-align:center">"""+str(data.weightSnapdeal)+" gms"+"""</td>
|
| 155 |
<td style="text-align:center">"""+str(data.courierCost*1.1236)+"""</td>
|
179 |
<td style="text-align:center">"""+str(round(data.courierCost*1.1236,2))+"""</td>
|
| 156 |
<td style="text-align:center">"""+str(data.logisticCostSnapdeal)+" gms"+"""</td>
|
180 |
<td style="text-align:center">"""+str(round(data.logisticCostSnapdeal,2))+"""</td>
|
| 157 |
</tr>"""
|
181 |
</tr>"""
|
| 158 |
message+="""</tbody></table>"""
|
182 |
message+="""</tbody></table>"""
|
| 159 |
message+="""
|
183 |
message+="""
|
| 160 |
<h3>High TP On Snapdeal</h3>
|
184 |
<h3>High TP On Snapdeal</h3>
|
| 161 |
<table border="1" style="width:100%;">
|
185 |
<table border="1" style="width:100%;">
|
| Line 176... |
Line 200... |
| 176 |
<th>Snapdeal Courier Charges</th>
|
200 |
<th>Snapdeal Courier Charges</th>
|
| 177 |
</tr></thead>
|
201 |
</tr></thead>
|
| 178 |
<tbody>"""
|
202 |
<tbody>"""
|
| 179 |
for data in filteredData:
|
203 |
for data in filteredData:
|
| 180 |
if data.transferPriceSnapdeal >= data.transferPrice:
|
204 |
if data.transferPriceSnapdeal >= data.transferPrice:
|
| 181 |
it = Item.query.filter_by(id=data.itemId).one()
|
- |
|
| 182 |
message+="""<tr>
|
205 |
message+="""<tr>
|
| 183 |
<td style="text-align:center">"""+str(data.itemId)+"""</td>
|
206 |
<td style="text-align:center">"""+str(data.itemId)+"""</td>
|
| 184 |
<td style="text-align:center">"""+xstr(it.brand)+" "+xstr(it.model_name)+" "+xstr(it.model_number)+" "+xstr(it.color)+"""</td>
|
207 |
<td style="text-align:center">"""+xstr(data.brand)+" "+xstr(data.modelName)+" "+xstr(data.modelNumber)+" "+xstr(data.color)+"""</td>
|
| 185 |
<td style="text-align:center">"""+str(data.sellingPrice)+"""</td>
|
208 |
<td style="text-align:center">"""+str(data.sellingPrice)+"""</td>
|
| 186 |
<td style="text-align:center">"""+str(data.sellingPriceSnapdeal)+"""</td>
|
209 |
<td style="text-align:center">"""+str(data.sellingPriceSnapdeal)+"""</td>
|
| 187 |
<td style="text-align:center">"""+str(data.transferPrice)+"""</td>
|
210 |
<td style="text-align:center">"""+str(data.transferPrice)+"""</td>
|
| 188 |
<td style="text-align:center">"""+str(data.transferPriceSnapdeal)+"""</td>
|
211 |
<td style="text-align:center">"""+str(data.transferPriceSnapdeal)+"""</td>
|
| 189 |
<td style="text-align:center">"""+str(data.commission*1.1236)+"""</td>
|
212 |
<td style="text-align:center">"""+str(round(data.commission*1.1236,2))+"""</td>
|
| 190 |
<td style="text-align:center">"""+str(round(float(data.fixedMargin)+float(data.collectionCharges),2))+"""</td>
|
213 |
<td style="text-align:center">"""+str(round(float(data.fixedMargin)+float(data.collectionCharges),2))+"""</td>
|
| 191 |
<td style="text-align:center">"""+str(data.commissionPercentage)+"%"+"""</td>
|
214 |
<td style="text-align:center">"""+str(data.commissionPercentage)+"%"+"""</td>
|
| 192 |
<td style="text-align:center">"""+str(round(float(data.fixedMarginPercentage)/1.1236,2))+"%"+"""</td>
|
215 |
<td style="text-align:center">"""+str(round(float(data.fixedMarginPercentage)/1.1236,2))+"%"+"""</td>
|
| 193 |
<td style="text-align:center">"""+str(it.weight*100)+" gms"+"""</td>
|
216 |
<td style="text-align:center">"""+str(data.weight*1000)+" gms"+"""</td>
|
| 194 |
<td style="text-align:center">"""+str(data.weightSnapdeal)+" gms"+"""</td>
|
217 |
<td style="text-align:center">"""+str(data.weightSnapdeal)+" gms"+"""</td>
|
| 195 |
<td style="text-align:center">"""+str(data.courierCost*1.1236)+"""</td>
|
218 |
<td style="text-align:center">"""+str(round(data.courierCost*1.1236,2))+"""</td>
|
| 196 |
<td style="text-align:center">"""+str(data.logisticCostSnapdeal)+"""</td>
|
219 |
<td style="text-align:center">"""+str(round(data.logisticCostSnapdeal,2))+"""</td>
|
| 197 |
</tr>"""
|
220 |
</tr>"""
|
| 198 |
message+="""</tbody></table>"""
|
221 |
message+="""</tbody></table>"""
|
| 199 |
message+="""
|
222 |
message+="""
|
| 200 |
<h3>Unable To Fetch Items</h3>
|
223 |
<h3>Unable To Fetch Items</h3>
|
| 201 |
<table border="1" style="width:100%;">
|
224 |
<table border="1" style="width:100%;">
|
| Line 211... |
Line 234... |
| 211 |
</tr></thead>
|
234 |
</tr></thead>
|
| 212 |
<tbody>"""
|
235 |
<tbody>"""
|
| 213 |
for data in exceptionList:
|
236 |
for data in exceptionList:
|
| 214 |
snapdealItem = data[0]
|
237 |
snapdealItem = data[0]
|
| 215 |
marketplaceItem = data[1]
|
238 |
marketplaceItem = data[1]
|
| 216 |
it = Item.query.filter_by(id=data.itemId).one()
|
239 |
ds_item = data[2]
|
| 217 |
message+="""<tr>
|
240 |
message+="""<tr>
|
| 218 |
<td style="text-align:center">"""+str(data.itemId)+"""</td>
|
241 |
<td style="text-align:center">"""+str(ds_item.id)+"""</td>
|
| 219 |
<td style="text-align:center">"""+xstr(it.brand)+" "+xstr(it.model_name)+" "+xstr(it.model_number)+" "+xstr(it.color)+"""</td>
|
242 |
<td style="text-align:center">"""+xstr(ds_item.brand)+" "+xstr(ds_item.model_name)+" "+xstr(ds_item.model_number)+" "+xstr(ds_item.color)+"""</td>
|
| 220 |
<td style="text-align:center">"""+str(snapdealItem.sellingPrice)+"""</td>
|
243 |
<td style="text-align:center">"""+str(snapdealItem.sellingPrice)+"""</td>
|
| 221 |
<td style="text-align:center">"""+str(snapdealItem.transferPrice)+"""</td>
|
244 |
<td style="text-align:center">"""+str(snapdealItem.transferPrice)+"""</td>
|
| 222 |
<td style="text-align:center">"""+str(snapdealItem.commission*1.1236)+"""</td>
|
245 |
<td style="text-align:center">"""+str(snapdealItem.commission*1.1236)+"""</td>
|
| 223 |
<td style="text-align:center">"""+str(marketplaceItem.commissionPercentage)+"%"+"""</td>
|
246 |
<td style="text-align:center">"""+str(marketplaceItem.commission)+"%"+"""</td>
|
| 224 |
<td style="text-align:center">"""+str(it.weight*100)+" gms"+"""</td>
|
247 |
<td style="text-align:center">"""+str(ds_item.weight*1000)+" gms"+"""</td>
|
| 225 |
<td style="text-align:center">"""+str(snapdealItem.courierCost*1.1236)+"""</td>
|
248 |
<td style="text-align:center">"""+str(snapdealItem.courierCost*1.1236)+"""</td>
|
| 226 |
</tr>"""
|
249 |
</tr>"""
|
| 227 |
message+="""</tbody></table></body></html>"""
|
250 |
message+="""</tbody></table></body></html>"""
|
| 228 |
print message
|
251 |
print message
|
| 229 |
mailServer = smtplib.SMTP("smtp.gmail.com", 587)
|
252 |
mailServer = smtplib.SMTP("smtp.gmail.com", 587)
|
| Line 254... |
Line 277... |
| 254 |
smtpServer.sendmail(sender, recipients, msg.as_string())
|
277 |
smtpServer.sendmail(sender, recipients, msg.as_string())
|
| 255 |
print "Successfully sent email"
|
278 |
print "Successfully sent email"
|
| 256 |
except:
|
279 |
except:
|
| 257 |
print "Error: unable to send email."
|
280 |
print "Error: unable to send email."
|
| 258 |
|
281 |
|
| - |
|
282 |
def write_report(filteredData,exceptionList):
|
| - |
|
283 |
wbk = xlwt.Workbook()
|
| - |
|
284 |
sheet = wbk.add_sheet('Low TP SD')
|
| - |
|
285 |
xstr = lambda s: s or ""
|
| - |
|
286 |
heading_xf = xlwt.easyxf('font: bold on; align: wrap off, vert centre, horiz center')
|
| - |
|
287 |
|
| - |
|
288 |
excel_integer_format = '0'
|
| - |
|
289 |
integer_style = xlwt.XFStyle()
|
| - |
|
290 |
integer_style.num_format_str = excel_integer_format
|
| - |
|
291 |
|
| - |
|
292 |
sheet.write(0, 0, "Item ID", heading_xf)
|
| - |
|
293 |
sheet.write(0, 1, "Category", heading_xf)
|
| - |
|
294 |
sheet.write(0, 2, "Product Group.", heading_xf)
|
| - |
|
295 |
sheet.write(0, 3, "SUPC", heading_xf)
|
| - |
|
296 |
sheet.write(0, 4, "Brand", heading_xf)
|
| - |
|
297 |
sheet.write(0, 5, "Product Name", heading_xf)
|
| - |
|
298 |
sheet.write(0, 6, "Our System SP", heading_xf)
|
| - |
|
299 |
sheet.write(0, 7, "Snapdeal SP", heading_xf)
|
| - |
|
300 |
sheet.write(0, 8, "Our TP", heading_xf)
|
| - |
|
301 |
sheet.write(0, 9, "Snapdeal TP", heading_xf)
|
| - |
|
302 |
sheet.write(0, 10, "Our System Commission", heading_xf)
|
| - |
|
303 |
sheet.write(0, 11, "Snapdeal Commission", heading_xf)
|
| - |
|
304 |
sheet.write(0, 12, "Our System Commission %", heading_xf)
|
| - |
|
305 |
sheet.write(0, 13, "Snapdeal Commission %", heading_xf)
|
| - |
|
306 |
sheet.write(0, 14, "Our System Weight (gms)", heading_xf)
|
| - |
|
307 |
sheet.write(0, 15, "Snapdeal Weight", heading_xf)
|
| - |
|
308 |
sheet.write(0, 16, "Our Courier Cost", heading_xf)
|
| - |
|
309 |
sheet.write(0, 17, "Snapdeal Courier Cost", heading_xf)
|
| - |
|
310 |
|
| - |
|
311 |
sheet_iterator=1
|
| - |
|
312 |
for data in filteredData:
|
| - |
|
313 |
if data.transferPriceSnapdeal < data.transferPrice:
|
| - |
|
314 |
sheet.write(sheet_iterator, 0, data.itemId)
|
| - |
|
315 |
sheet.write(sheet_iterator, 1, data.parentCategory)
|
| - |
|
316 |
sheet.write(sheet_iterator, 2, data.supc)
|
| - |
|
317 |
sheet.write(sheet_iterator, 3, data.brand)
|
| - |
|
318 |
sheet.write(sheet_iterator, 4, data.brand)
|
| - |
|
319 |
sheet.write(sheet_iterator, 5, xstr(data.brand)+" "+xstr(data.modelName)+" "+xstr(data.modelNumber)+" "+xstr(data.color))
|
| - |
|
320 |
sheet.write(sheet_iterator, 6, data.sellingPrice)
|
| - |
|
321 |
sheet.write(sheet_iterator, 7, data.sellingPriceSnapdeal)
|
| - |
|
322 |
sheet.write(sheet_iterator, 8, data.transferPrice)
|
| - |
|
323 |
sheet.write(sheet_iterator, 9, data.transferPriceSnapdeal)
|
| - |
|
324 |
sheet.write(sheet_iterator, 10, round(data.commission*1.1236,2))
|
| - |
|
325 |
sheet.write(sheet_iterator, 11, round(float(data.fixedMargin)+float(data.collectionCharges),2))
|
| - |
|
326 |
sheet.write(sheet_iterator, 12, data.commissionPercentage)
|
| - |
|
327 |
sheet.write(sheet_iterator, 13, round(float(data.fixedMarginPercentage)/1.1236,2))
|
| - |
|
328 |
sheet.write(sheet_iterator, 14, data.weight*1000)
|
| - |
|
329 |
sheet.write(sheet_iterator, 15, data.weightSnapdeal)
|
| - |
|
330 |
sheet.write(sheet_iterator, 16, round(data.courierCost*1.1236,2))
|
| - |
|
331 |
sheet.write(sheet_iterator, 17, round(data.logisticCostSnapdeal,2))
|
| - |
|
332 |
sheet_iterator+=1
|
| - |
|
333 |
|
| - |
|
334 |
sheet = wbk.add_sheet('High TP SD')
|
| - |
|
335 |
|
| - |
|
336 |
heading_xf = xlwt.easyxf('font: bold on; align: wrap off, vert centre, horiz center')
|
| - |
|
337 |
|
| - |
|
338 |
excel_integer_format = '0'
|
| - |
|
339 |
integer_style = xlwt.XFStyle()
|
| - |
|
340 |
integer_style.num_format_str = excel_integer_format
|
| - |
|
341 |
xstr = lambda s: s or ""
|
| - |
|
342 |
|
| - |
|
343 |
sheet.write(0, 0, "Item ID", heading_xf)
|
| - |
|
344 |
sheet.write(0, 1, "Category", heading_xf)
|
| - |
|
345 |
sheet.write(0, 2, "Product Group.", heading_xf)
|
| - |
|
346 |
sheet.write(0, 3, "SUPC", heading_xf)
|
| - |
|
347 |
sheet.write(0, 4, "Brand", heading_xf)
|
| - |
|
348 |
sheet.write(0, 5, "Product Name", heading_xf)
|
| - |
|
349 |
sheet.write(0, 6, "Our System SP", heading_xf)
|
| - |
|
350 |
sheet.write(0, 7, "Snapdeal SP", heading_xf)
|
| - |
|
351 |
sheet.write(0, 8, "Our TP", heading_xf)
|
| - |
|
352 |
sheet.write(0, 9, "Snapdeal TP", heading_xf)
|
| - |
|
353 |
sheet.write(0, 10, "Our System Commission", heading_xf)
|
| - |
|
354 |
sheet.write(0, 11, "Snapdeal Commission", heading_xf)
|
| - |
|
355 |
sheet.write(0, 12, "Our System Commission %", heading_xf)
|
| - |
|
356 |
sheet.write(0, 13, "Snapdeal Commission %", heading_xf)
|
| - |
|
357 |
sheet.write(0, 14, "Our System Weight (gms)", heading_xf)
|
| - |
|
358 |
sheet.write(0, 15, "Snapdeal Weight", heading_xf)
|
| - |
|
359 |
sheet.write(0, 16, "Our Courier Cost", heading_xf)
|
| - |
|
360 |
sheet.write(0, 17, "Snapdeal Courier Cost", heading_xf)
|
| - |
|
361 |
|
| - |
|
362 |
sheet_iterator=1
|
| - |
|
363 |
for data in filteredData:
|
| - |
|
364 |
if data.transferPriceSnapdeal > data.transferPrice:
|
| - |
|
365 |
sheet.write(sheet_iterator, 0, data.itemId)
|
| - |
|
366 |
sheet.write(sheet_iterator, 1, data.parentCategory)
|
| - |
|
367 |
sheet.write(sheet_iterator, 2, data.supc)
|
| - |
|
368 |
sheet.write(sheet_iterator, 3, data.brand)
|
| - |
|
369 |
sheet.write(sheet_iterator, 4, data.brand)
|
| - |
|
370 |
sheet.write(sheet_iterator, 5, xstr(data.brand)+" "+xstr(data.modelName)+" "+xstr(data.modelNumber)+" "+xstr(data.color))
|
| - |
|
371 |
sheet.write(sheet_iterator, 6, data.sellingPrice)
|
| - |
|
372 |
sheet.write(sheet_iterator, 7, data.sellingPriceSnapdeal)
|
| - |
|
373 |
sheet.write(sheet_iterator, 8, data.transferPrice)
|
| - |
|
374 |
sheet.write(sheet_iterator, 9, data.transferPriceSnapdeal)
|
| - |
|
375 |
sheet.write(sheet_iterator, 10, round(data.commission*1.1236,2))
|
| - |
|
376 |
sheet.write(sheet_iterator, 11, round(float(data.fixedMargin)+float(data.collectionCharges),2))
|
| - |
|
377 |
sheet.write(sheet_iterator, 12, data.commissionPercentage)
|
| - |
|
378 |
sheet.write(sheet_iterator, 13, round(float(data.fixedMarginPercentage)/1.1236,2))
|
| - |
|
379 |
sheet.write(sheet_iterator, 14, data.weight*1000)
|
| - |
|
380 |
sheet.write(sheet_iterator, 15, data.weightSnapdeal)
|
| - |
|
381 |
sheet.write(sheet_iterator, 16, round(data.courierCost*1.1236,2))
|
| - |
|
382 |
sheet.write(sheet_iterator, 17, round(data.logisticCostSnapdeal,2))
|
| - |
|
383 |
sheet_iterator+=1
|
| - |
|
384 |
|
| - |
|
385 |
sheet = wbk.add_sheet('Exceptions')
|
| - |
|
386 |
|
| - |
|
387 |
heading_xf = xlwt.easyxf('font: bold on; align: wrap off, vert centre, horiz center')
|
| - |
|
388 |
|
| - |
|
389 |
excel_integer_format = '0'
|
| - |
|
390 |
integer_style = xlwt.XFStyle()
|
| - |
|
391 |
integer_style.num_format_str = excel_integer_format
|
| - |
|
392 |
xstr = lambda s: s or ""
|
| - |
|
393 |
|
| - |
|
394 |
sheet.write(0, 0, "Item ID", heading_xf)
|
| - |
|
395 |
sheet.write(0, 1, "SUPC", heading_xf)
|
| - |
|
396 |
sheet.write(0, 2, "Brand", heading_xf)
|
| - |
|
397 |
sheet.write(0, 3, "Product Name", heading_xf)
|
| - |
|
398 |
sheet.write(0, 4, "Our System SP", heading_xf)
|
| - |
|
399 |
sheet.write(0, 5, "Our TP", heading_xf)
|
| - |
|
400 |
sheet.write(0, 6, "Our System Commission", heading_xf)
|
| - |
|
401 |
sheet.write(0, 7, "Our System Commission %", heading_xf)
|
| - |
|
402 |
sheet.write(0, 8, "Our System Weight (gms)", heading_xf)
|
| - |
|
403 |
sheet.write(0, 9, "Our Courier Cost", heading_xf)
|
| - |
|
404 |
|
| - |
|
405 |
sheet_iterator=1
|
| - |
|
406 |
for data in exceptionList:
|
| - |
|
407 |
snapdealItem = data[0]
|
| - |
|
408 |
marketplaceItem = data[1]
|
| - |
|
409 |
ds_item = data[2]
|
| - |
|
410 |
sheet.write(sheet_iterator, 0, ds_item.id)
|
| - |
|
411 |
sheet.write(sheet_iterator, 1, snapdealItem.supc)
|
| - |
|
412 |
sheet.write(sheet_iterator, 2, ds_item.brand)
|
| - |
|
413 |
sheet.write(sheet_iterator, 3, xstr(ds_item.brand)+" "+xstr(ds_item.model_name)+" "+xstr(ds_item.model_number)+" "+xstr(data.color))
|
| - |
|
414 |
sheet.write(sheet_iterator, 4, snapdealItem.sellingPrice)
|
| - |
|
415 |
sheet.write(sheet_iterator, 5, snapdealItem.transferPrice)
|
| - |
|
416 |
sheet.write(sheet_iterator, 6, round(snapdealItem.commission*1.1236,2))
|
| - |
|
417 |
sheet.write(sheet_iterator, 7, marketplaceItem.commission)
|
| - |
|
418 |
sheet.write(sheet_iterator, 8, (ds_item.weight*1000))
|
| - |
|
419 |
sheet.write(sheet_iterator, 9, round(data.courierCost*1.1236,2))
|
| - |
|
420 |
|
| - |
|
421 |
filename = "/tmp/snapdeal-tp-reconciliation-" + str(datetime.now()) + ".xls"
|
| - |
|
422 |
wbk.save(filename)
|
| - |
|
423 |
|
| - |
|
424 |
try:
|
| - |
|
425 |
EmailAttachmentSender.mail("build@shop2020.in", "cafe@nes", ["kshitij.sood@saholic.com"], " Snapdeal TP Reconciliation "+ str(datetime.now()), "", [get_attachment_part(filename)], [""], [])
|
| - |
|
426 |
#EmailAttachmentSender.mail("build@shop2020.in", "cafe@nes", ["chandan.kumar@saholic.com","manoj.kumar@saholic.com","yukti.jain@saholic.com","ankush.dhingra@saholic.com","manoj.pal@saholic.com"], " Snapdeal TP Reconciliation "+ str(datetime.now()), "", [get_attachment_part(filename)], ["rajneesh.arora@saholic.com","rajveer.singh@saholic.com","vikram.raghav@saholic.com","kshitij.sood@saholic.com","chaitnaya.vats@saholic.com","khushal.bhatia@saholic.com"], [])
|
| - |
|
427 |
except Exception as e:
|
| - |
|
428 |
print e
|
| - |
|
429 |
print "Unable to send report.Trying with local SMTP"
|
| - |
|
430 |
smtpServer = smtplib.SMTP('localhost')
|
| - |
|
431 |
smtpServer.set_debuglevel(1)
|
| - |
|
432 |
sender = 'support@shop2020.in'
|
| - |
|
433 |
recipients = ['kshitij.sood@saholic.com']
|
| - |
|
434 |
msg = MIMEMultipart()
|
| - |
|
435 |
msg['Subject'] = "Snapdeal TP Reconciliation" + ' - ' + str(datetime.now())
|
| - |
|
436 |
msg['From'] = sender
|
| - |
|
437 |
#recipients = ['rajneesh.arora@saholic.com','rajveer.singh@saholic.com','vikram.raghav@saholic.com','kshitij.sood@saholic.com','khushal.bhatia@saholic.com','chaitnaya.vats@saholic.com','chandan.kumar@saholic.com','manoj.kumar@saholic.com','yukti.jain@saholic.com','ankush.dhingra@saholic.com','manoj.pal@saholic.com']
|
| - |
|
438 |
msg['To'] = ",".join(recipients)
|
| - |
|
439 |
fileMsg = email.mime.base.MIMEBase('application','vnd.ms-excel')
|
| - |
|
440 |
fileMsg.set_payload(file(filename).read())
|
| - |
|
441 |
email.encoders.encode_base64(fileMsg)
|
| - |
|
442 |
fileMsg.add_header('Content-Disposition','attachment;filename=snapdeal.xls')
|
| - |
|
443 |
msg.attach(fileMsg)
|
| - |
|
444 |
try:
|
| - |
|
445 |
smtpServer.sendmail(sender, recipients, msg.as_string())
|
| - |
|
446 |
print "Successfully sent email"
|
| - |
|
447 |
except:
|
| - |
|
448 |
print "Error: unable to send email."
|
| - |
|
449 |
|
| - |
|
450 |
|
| - |
|
451 |
|
| - |
|
452 |
|
| - |
|
453 |
|
| - |
|
454 |
|
| - |
|
455 |
|
| - |
|
456 |
|
| - |
|
457 |
|
| - |
|
458 |
|
| - |
|
459 |
|
| - |
|
460 |
|
| - |
|
461 |
|
| - |
|
462 |
|
| - |
|
463 |
|
| 259 |
def main():
|
464 |
def main():
|
| 260 |
print "Opening snapdeal seller login page"
|
465 |
print "Opening snapdeal seller login page"
|
| 261 |
br = login("http://selleraccounts.snapdeal.com/")
|
466 |
br = login("http://selleraccounts.snapdeal.com/")
|
| 262 |
exceptionList, fetchedItems = populateStuff(br)
|
467 |
exceptionList, fetchedItems = populateStuff(br)
|
| 263 |
filteredData = filterData(fetchedItems)
|
468 |
filteredData = filterData(fetchedItems)
|
| 264 |
sendMail(filteredData,exceptionList)
|
469 |
sendMail(filteredData,exceptionList)
|
| - |
|
470 |
write_report(filteredData,exceptionList)
|
| 265 |
|
471 |
|
| 266 |
|
472 |
|
| 267 |
if __name__ == "__main__":
|
473 |
if __name__ == "__main__":
|
| 268 |
main()
|
474 |
main()
|
| 269 |
|
475 |
|