Subversion Repositories SmartDukaan

Rev

Rev 10417 | Rev 10420 | 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
            print "Inside try for fetch data"
97
            snapdealInfo = fetchData(br,snapdealItem.supc)
98
        except Exception as e:
99
            exceptionList.append(item)
100
            print "Unable to fetch details ",e
101
            continue
102
        snapdealInfo.sellingPrice = snapdealItem.sellingPrice
103
        snapdealInfo.courierCost = snapdealItem.courierCost
104
        snapdealInfo.transferPrice = snapdealItem.transferPrice
105
        snapdealInfo.commissionPercentage = marketplaceItem.commission
106
        snapdealInfo.commission = snapdealItem.commission
107
        snapdealInfo.itemId = snapdealItem.item_id
10414 kshitij.so 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
10404 kshitij.so 115
        fetchedItems.append(snapdealInfo)
10401 amar.kumar 116
    return exceptionList, fetchedItems
117
 
118
def fetchData(br,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)
120
    sleep(1)
121
    response = br.open(url)
122
    dataform = str(response.read()).strip("'<>() ").replace('\'', '\"')
123
    struct = json.loads(dataform)
124
    sdObj = struct['rows'][0]
125
    print sdObj
10414 kshitij.so 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)
10401 amar.kumar 128
    return snapdealInfo
129
 
130
def filterData(fetchedItems):
10414 kshitij.so 131
    filterList = []
10401 amar.kumar 132
    for data in fetchedItems:
10414 kshitij.so 133
        print data.itemId
134
        print data.transferPrice
135
        print data.transferPriceSnapdeal
10401 amar.kumar 136
        if ( data.transferPrice - data.transferPriceSnapdeal >= -3 ) and (data.transferPrice - data.transferPriceSnapdeal <= 3):
10414 kshitij.so 137
            continue
138
        filterList.append(data)
139
    return filterList
10401 amar.kumar 140
 
141
def sendMail(filteredData,exceptionList):
142
    xstr = lambda s: s or ""
143
    message="""<html>
144
            <body>
145
            <h3>Low TP On Snapdeal</h3>
146
            <table border="1" style="width:100%;">
147
            <thead>
148
            <tr><th>Item Id</th>
149
            <th>Product Name</th>
150
            <th>Our System Selling Price</th>
151
            <th>Selling Price Snapdeal</th>
152
            <th>Our System Transfer Price</th>
153
            <th>Snapdeal Transfer Price</th>
154
            <th>Our System Commission</th>
155
            <th>Snapdeal Commission</th>
156
            <th>Our System Commission %</th>
157
            <th>Snapdeal Commission %</th>
158
            <th>Our System Weight</th>
159
            <th>Snapdeal Weight</th>
160
            <th>Our Courier Cost</th>
161
            <th>Snapdeal Courier Charges</th>
162
            </tr></thead>
163
            <tbody>"""
164
    for data in filteredData:
165
        if data.transferPriceSnapdeal < data.transferPrice:
166
            message+="""<tr>
167
            <td style="text-align:center">"""+str(data.itemId)+"""</td>
10414 kshitij.so 168
            <td style="text-align:center">"""+xstr(data.brand)+" "+xstr(data.modelName)+" "+xstr(data.modelNumber)+" "+xstr(data.color)+"""</td>
10401 amar.kumar 169
            <td style="text-align:center">"""+str(data.sellingPrice)+"""</td>
170
            <td style="text-align:center">"""+str(data.sellingPriceSnapdeal)+"""</td>
171
            <td style="text-align:center">"""+str(data.transferPrice)+"""</td>
172
            <td style="text-align:center">"""+str(data.transferPriceSnapdeal)+"""</td>
10414 kshitij.so 173
            <td style="text-align:center">"""+str(round(data.commission*1.1236,2))+"""</td>
10401 amar.kumar 174
            <td style="text-align:center">"""+str(round(float(data.fixedMargin)+float(data.collectionCharges),2))+"""</td>
175
            <td style="text-align:center">"""+str(data.commissionPercentage)+"%"+"""</td>
176
            <td style="text-align:center">"""+str(round(float(data.fixedMarginPercentage)/1.1236,2))+"%"+"""</td>
10414 kshitij.so 177
            <td style="text-align:center">"""+str(data.weight*1000)+" gms"+"""</td>
10401 amar.kumar 178
            <td style="text-align:center">"""+str(data.weightSnapdeal)+" gms"+"""</td>
10414 kshitij.so 179
            <td style="text-align:center">"""+str(round(data.courierCost*1.1236,2))+"""</td>
180
            <td style="text-align:center">"""+str(round(data.logisticCostSnapdeal,2))+"""</td>
10401 amar.kumar 181
            </tr>"""
182
    message+="""</tbody></table>"""
183
    message+="""
184
            <h3>High TP On Snapdeal</h3>
185
            <table border="1" style="width:100%;">
186
            <thead>
187
            <tr><th>Item Id</th>
188
            <th>Product Name</th>
189
            <th>Our System Selling Price</th>
190
            <th>Selling Price Snapdeal</th>
191
            <th>Our System Transfer Price</th>
192
            <th>Snapdeal Transfer Price</th>
193
            <th>Our System Commission</th>
194
            <th>Snapdeal Commission</th>
195
            <th>Our System Commission %</th>
196
            <th>Snapdeal Commission %</th>
197
            <th>Our System Weight</th>
198
            <th>Snapdeal Weight</th>
199
            <th>Our Courier Cost</th>
200
            <th>Snapdeal Courier Charges</th>
201
            </tr></thead>
202
            <tbody>"""
203
    for data in filteredData:
204
        if data.transferPriceSnapdeal >= data.transferPrice:
205
            message+="""<tr>
206
            <td style="text-align:center">"""+str(data.itemId)+"""</td>
10414 kshitij.so 207
            <td style="text-align:center">"""+xstr(data.brand)+" "+xstr(data.modelName)+" "+xstr(data.modelNumber)+" "+xstr(data.color)+"""</td>
10401 amar.kumar 208
            <td style="text-align:center">"""+str(data.sellingPrice)+"""</td>
209
            <td style="text-align:center">"""+str(data.sellingPriceSnapdeal)+"""</td>
210
            <td style="text-align:center">"""+str(data.transferPrice)+"""</td>
211
            <td style="text-align:center">"""+str(data.transferPriceSnapdeal)+"""</td>
10414 kshitij.so 212
            <td style="text-align:center">"""+str(round(data.commission*1.1236,2))+"""</td>
10401 amar.kumar 213
            <td style="text-align:center">"""+str(round(float(data.fixedMargin)+float(data.collectionCharges),2))+"""</td>
214
            <td style="text-align:center">"""+str(data.commissionPercentage)+"%"+"""</td>
215
            <td style="text-align:center">"""+str(round(float(data.fixedMarginPercentage)/1.1236,2))+"%"+"""</td>
10414 kshitij.so 216
            <td style="text-align:center">"""+str(data.weight*1000)+" gms"+"""</td>
10401 amar.kumar 217
            <td style="text-align:center">"""+str(data.weightSnapdeal)+" gms"+"""</td>
10414 kshitij.so 218
            <td style="text-align:center">"""+str(round(data.courierCost*1.1236,2))+"""</td>
219
            <td style="text-align:center">"""+str(round(data.logisticCostSnapdeal,2))+"""</td>
10401 amar.kumar 220
            </tr>"""
221
    message+="""</tbody></table>"""
222
    message+="""
223
            <h3>Unable To Fetch Items</h3>
224
            <table border="1" style="width:100%;">
225
            <thead>
226
            <tr><th>Item Id</th>
227
            <th>Product Name</th>
228
            <th>Our System Selling Price</th>
229
            <th>Our System Transfer Price</th>
230
            <th>Our System Commission</th>
231
            <th>Our System Commission %</th>
232
            <th>Our System Weight</th>
233
            <th>Our Courier Cost</th>
234
            </tr></thead>
235
            <tbody>"""
236
    for data in exceptionList:
237
        snapdealItem = data[0]
238
        marketplaceItem = data[1]
10414 kshitij.so 239
        ds_item = data[2]
10401 amar.kumar 240
        message+="""<tr>
10414 kshitij.so 241
            <td style="text-align:center">"""+str(ds_item.id)+"""</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>
10401 amar.kumar 243
            <td style="text-align:center">"""+str(snapdealItem.sellingPrice)+"""</td>
244
            <td style="text-align:center">"""+str(snapdealItem.transferPrice)+"""</td>
10419 kshitij.so 245
            <td style="text-align:center">"""+str(round(snapdealItem.commission*1.1236,2))+"""</td>
10414 kshitij.so 246
            <td style="text-align:center">"""+str(marketplaceItem.commission)+"%"+"""</td>
247
            <td style="text-align:center">"""+str(ds_item.weight*1000)+" gms"+"""</td>
10419 kshitij.so 248
            <td style="text-align:center">"""+str(round(snapdealItem.courierCost*1.1236,2))+"""</td>
10401 amar.kumar 249
            </tr>"""
250
    message+="""</tbody></table></body></html>"""
251
    print message
252
    mailServer = smtplib.SMTP("smtp.gmail.com", 587)
253
    mailServer.ehlo()
254
    mailServer.starttls()
255
    mailServer.ehlo()
256
 
257
    recipients = ['kshitij.sood@saholic.com']
258
    #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']
259
    msg = MIMEMultipart()
260
    msg['Subject'] = "Snapdeal TP Reconciliation" + ' - ' + str(datetime.now())
261
    msg['From'] = ""
262
    msg['To'] = ",".join(recipients)
263
    msg.preamble = "Snapdeal TP Reconciliation" + ' - ' + str(datetime.now())
264
    html_msg = MIMEText(message, 'html')
265
    msg.attach(html_msg)
266
    try:
267
        mailServer.login("build@shop2020.in", "cafe@nes")
268
        #mailServer.sendmail("cafe@nes", ['kshitij.sood@saholic.com'], msg.as_string())
269
        mailServer.sendmail("cafe@nes", recipients, msg.as_string())
270
    except Exception as e:
271
        print e
272
        print "Unable to send Snapdeal TP Reconciliation mail.Lets try with local SMTP."
273
        smtpServer = smtplib.SMTP('localhost')
274
        smtpServer.set_debuglevel(1)
275
        sender = 'support@shop2020.in'
276
    try:
277
        smtpServer.sendmail(sender, recipients, msg.as_string())
278
        print "Successfully sent email"
279
    except:
280
        print "Error: unable to send email."
281
 
10414 kshitij.so 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)
10415 kshitij.so 413
        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 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))
10417 kshitij.so 419
        sheet.write(sheet_iterator, 9, round(snapdealItem.courierCost*1.1236,2))
10419 kshitij.so 420
        sheet_iterator+=1
10414 kshitij.so 421
 
422
    filename = "/tmp/snapdeal-tp-reconciliation-" + str(datetime.now()) + ".xls"
423
    wbk.save(filename)
424
 
425
    try:
426
        EmailAttachmentSender.mail("build@shop2020.in", "cafe@nes", ["kshitij.sood@saholic.com"], " Snapdeal TP Reconciliation "+ str(datetime.now()), "", [get_attachment_part(filename)], [""], [])
427
        #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"], [])
428
    except Exception as e:
429
        print e
430
        print "Unable to send report.Trying with local SMTP"
431
        smtpServer = smtplib.SMTP('localhost')
432
        smtpServer.set_debuglevel(1)
433
        sender = 'support@shop2020.in'
434
        recipients = ['kshitij.sood@saholic.com']
435
        msg = MIMEMultipart()
436
        msg['Subject'] = "Snapdeal TP Reconciliation" + ' - ' + str(datetime.now())
437
        msg['From'] = sender
438
        #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']
439
        msg['To'] = ",".join(recipients)
440
        fileMsg = email.mime.base.MIMEBase('application','vnd.ms-excel')
441
        fileMsg.set_payload(file(filename).read())
442
        email.encoders.encode_base64(fileMsg)
10419 kshitij.so 443
        fileMsg.add_header('Content-Disposition','attachment;filename=snapdeal_tp_recon.xls')
10414 kshitij.so 444
        msg.attach(fileMsg)
445
        try:
446
            smtpServer.sendmail(sender, recipients, msg.as_string())
447
            print "Successfully sent email"
448
        except:
449
            print "Error: unable to send email."
450
 
451
 
452
 
453
 
454
 
455
 
456
 
457
 
458
 
459
 
460
 
461
 
462
 
463
 
464
 
10401 amar.kumar 465
def main():
466
    print "Opening snapdeal seller login page"
467
    br = login("http://selleraccounts.snapdeal.com/")
468
    exceptionList, fetchedItems = populateStuff(br)
469
    filteredData = filterData(fetchedItems)
470
    sendMail(filteredData,exceptionList)
10414 kshitij.so 471
    write_report(filteredData,exceptionList)
10401 amar.kumar 472
 
473
 
474
if __name__ == "__main__":
475
    main()
476
 
477