Subversion Repositories SmartDukaan

Rev

Rev 10419 | Rev 10428 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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