Subversion Repositories SmartDukaan

Rev

Rev 14731 | Rev 14750 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 14731 Rev 14742
Line 2... Line 2...
2
import xlwt
2
import xlwt
3
from datetime import datetime
3
from datetime import datetime
4
from email.mime.multipart import MIMEMultipart
4
from email.mime.multipart import MIMEMultipart
5
import email.encoders
5
import email.encoders
6
import smtplib
6
import smtplib
-
 
7
from dtr.utils.utils import getCashBack
-
 
8
from dtr.storage.MemCache import MemCache
-
 
9
 
7
 
10
 
8
con = None
11
con = None
9
 
12
 
10
statusMap = {1:'Active',2:'EOL',3:'In Process',4:'Exclusive'}
13
statusMap = {1:'Active',2:'EOL',3:'In Process',4:'Exclusive'}
-
 
14
mc = MemCache("127.0.0.1")
11
 
15
 
12
class __SkuInfo:
16
class __SkuInfo:
13
    
17
    
14
    def __init__(self, _id, skuBundleId, category_id, mrp, available_price, source_id, rank, maxNlc, minNlc, schemeAmount, minDiscount, \
18
    def __init__(self, _id, skuBundleId, category_id, mrp, available_price, source_id, rank, maxNlc, minNlc, schemeAmount, minDiscount, \
15
                 maxDiscount, discountType, dp, nlcPoints, bestSellerPoints, totalPoints,in_stock,maxprice,showDeal, catalogBestSellerPoints):
19
                 maxDiscount, discountType, dp, nlcPoints, bestSellerPoints, totalPoints,in_stock,maxprice,showDeal, catalogBestSellerPoints, \
-
 
20
                 showDealOld):
16
        self._id = _id
21
        self._id = _id
17
        self.skuBundleId = skuBundleId
22
        self.skuBundleId = skuBundleId
18
        self.category_id = category_id
23
        self.category_id = category_id
19
        self.mrp = mrp
24
        self.mrp = mrp
20
        self.available_price = available_price
25
        self.available_price = available_price
Line 31... Line 36...
31
        self.bestSellerPoints = bestSellerPoints
36
        self.bestSellerPoints = bestSellerPoints
32
        self.totalPoints = totalPoints
37
        self.totalPoints = totalPoints
33
        self.in_stock = in_stock
38
        self.in_stock = in_stock
34
        self.maxprice = maxprice
39
        self.maxprice = maxprice
35
        self.showDeal = showDeal
40
        self.showDeal = showDeal
36
        self.catalogBestSellerPoints = catalogBestSellerPoints  
41
        self.catalogBestSellerPoints = catalogBestSellerPoints
-
 
42
        self.showDealOld = showDealOld  
37
 
43
 
38
def get_mongo_connection(host='localhost', port=27017):
44
def get_mongo_connection(host='localhost', port=27017):
39
    global con
45
    global con
40
    if con is None:
46
    if con is None:
41
        print "Establishing connection %s host and port %d" %(host,port)
47
        print "Establishing connection %s host and port %d" %(host,port)
Line 51... Line 57...
51
    data = get_mongo_connection().Catalog.Deals.find().sort([('totalPoints',pymongo.DESCENDING)])
57
    data = get_mongo_connection().Catalog.Deals.find().sort([('totalPoints',pymongo.DESCENDING)])
52
    print data.count()
58
    print data.count()
53
    for x in data:
59
    for x in data:
54
        s_info = __SkuInfo(x['_id'], x['skuBundleId'], x['category_id'],x['mrp'],x['available_price'],x['source_id'],x['rank'],x['maxNlc'], \
60
        s_info = __SkuInfo(x['_id'], x['skuBundleId'], x['category_id'],x['mrp'],x['available_price'],x['source_id'],x['rank'],x['maxNlc'], \
55
                           x['minNlc'], x['schemeAmount'],x['minDiscount'],x['maxDiscount'],x['discountType'],x['dp'],x['nlcPoints'],x['bestSellerPoints'], \
61
                           x['minNlc'], x['schemeAmount'],x['minDiscount'],x['maxDiscount'],x['discountType'],x['dp'],x['nlcPoints'],x['bestSellerPoints'], \
56
                           x['totalPoints'],x['in_stock'],x['maxprice'],x['showDeal'],x['catalogBestSellerPoints'])
62
                           x['totalPoints'],x['in_stock'],x['maxprice'],x['showDeal'],x['catalogBestSellerPoints'],x['showDealOld'])
57
        p.append(s_info)
63
        p.append(s_info)
58
    
64
    
59
    wbk = xlwt.Workbook()
65
    wbk = xlwt.Workbook()
60
    sheet = wbk.add_sheet('Deals')
66
    sheet = wbk.add_sheet('Deals')
61
    xstr = lambda s: s or ""
67
    xstr = lambda s: s or ""
Line 76... Line 82...
76
    sheet.write(0, 8, "MarketPlace Identifier", heading_xf)
82
    sheet.write(0, 8, "MarketPlace Identifier", heading_xf)
77
    sheet.write(0, 9, "MarketPlace Secondary Identifier", heading_xf)
83
    sheet.write(0, 9, "MarketPlace Secondary Identifier", heading_xf)
78
    sheet.write(0, 10, "Product Name (Marketplace)", heading_xf)
84
    sheet.write(0, 10, "Product Name (Marketplace)", heading_xf)
79
    sheet.write(0, 11, "Url", heading_xf)
85
    sheet.write(0, 11, "Url", heading_xf)
80
    sheet.write(0, 12, "Price", heading_xf)
86
    sheet.write(0, 12, "Price", heading_xf)
-
 
87
    sheet.write(0, 13, "After Cashback", heading_xf)
81
    sheet.write(0, 13, "Mrp", heading_xf)
88
    sheet.write(0, 14, "Mrp", heading_xf)
82
    sheet.write(0, 14, "DP", heading_xf)
89
    sheet.write(0, 15, "DP", heading_xf)
83
    sheet.write(0, 15, "Scheme Amount", heading_xf)
90
    sheet.write(0, 16, "Scheme Amount", heading_xf)
84
    sheet.write(0, 16, "Discount Type", heading_xf)
91
    sheet.write(0, 17, "Discount Type", heading_xf)
85
    sheet.write(0, 17, "Min Discount", heading_xf)
92
    sheet.write(0, 18, "Min Discount", heading_xf)
86
    sheet.write(0, 18, "Max Discount", heading_xf)
93
    sheet.write(0, 19, "Max Discount", heading_xf)
87
    sheet.write(0, 19, "Max Nlc", heading_xf)
94
    sheet.write(0, 20, "Max Nlc", heading_xf)
88
    sheet.write(0, 20, "Min Nlc", heading_xf)
95
    sheet.write(0, 21, "Min Nlc", heading_xf)
89
    sheet.write(0, 21, "Max Price", heading_xf)
96
    sheet.write(0, 22, "Max Price", heading_xf)
90
    sheet.write(0, 22, "Rank", heading_xf)
97
    sheet.write(0, 23, "Rank", heading_xf)
91
    sheet.write(0, 23, "Nlc Points", heading_xf)
98
    sheet.write(0, 24, "Nlc Points", heading_xf)
92
    sheet.write(0, 24, "Best Seller Points", heading_xf)
99
    sheet.write(0, 25, "Best Seller Points", heading_xf)
93
    sheet.write(0, 25, "Catalog Best Seller Points", heading_xf)
100
    sheet.write(0, 26, "Catalog Best Seller Points", heading_xf)
94
    sheet.write(0, 26, "Total Points", heading_xf)
101
    sheet.write(0, 27, "Total Points", heading_xf)
95
    sheet.write(0, 27, "Show Deals", heading_xf)
102
    sheet.write(0, 28, "Show Deals", heading_xf)
-
 
103
    sheet.write(0, 29, "Show Deals Old", heading_xf)
96
    
104
    
97
    it = 1
105
    it = 1
98
    for x in p:
106
    for x in p:
99
        y = list(get_mongo_connection().Catalog.MasterData.find({'_id':x._id}))
107
        y = list(get_mongo_connection().Catalog.MasterData.find({'_id':x._id}))
100
        sheet.write(it, 0, x._id)
108
        sheet.write(it, 0, x._id)
Line 115... Line 123...
115
        sheet.write(it, 8, y[0]['identifier'])
123
        sheet.write(it, 8, y[0]['identifier'])
116
        sheet.write(it, 9, y[0]['secondaryIdentifier'])
124
        sheet.write(it, 9, y[0]['secondaryIdentifier'])
117
        sheet.write(it, 10, y[0]['source_product_name'])
125
        sheet.write(it, 10, y[0]['source_product_name'])
118
        sheet.write(it, 11, y[0]['url'])
126
        sheet.write(it, 11, y[0]['url'])
119
        sheet.write(it, 12, y[0]['available_price'])
127
        sheet.write(it, 12, y[0]['available_price'])
-
 
128
        cashBack = getCashBack(x._id, x.source_id, x.category_id, mc, 'localhost')
-
 
129
        if not cashBack or cashBack.get('cash_back_status')!=1:
-
 
130
            pass
-
 
131
        else:
-
 
132
            if cashBack['cash_back_type'] ==1:
-
 
133
                y[0]['available_price'] = y[0]['available_price'] - y[0]['available_price'] * float(cashBack['cash_back'])/100
-
 
134
            elif cashBack['cash_back_type'] ==2:
-
 
135
                y[0]['available_price'] = y[0]['available_price'] - float(cashBack['cash_back'])
-
 
136
            else:
-
 
137
                pass
-
 
138
        sheet.write(it, 13, y[0]['available_price'])
120
        sheet.write(it, 13, x.mrp)
139
        sheet.write(it, 14, x.mrp)
121
        sheet.write(it, 14, x.dp)
140
        sheet.write(it, 15, x.dp)
122
        sheet.write(it, 15, x.schemeAmount)
141
        sheet.write(it, 16, x.schemeAmount)
123
        sheet.write(it, 16, x.discountType)
142
        sheet.write(it, 17, x.discountType)
124
        sheet.write(it, 17, x.minDiscount)
143
        sheet.write(it, 18, x.minDiscount)
125
        sheet.write(it, 18, x.maxDiscount)
144
        sheet.write(it, 19, x.maxDiscount)
126
        sheet.write(it, 19, x.maxNlc)
145
        sheet.write(it, 20, x.maxNlc)
127
        sheet.write(it, 20, x.minNlc)
146
        sheet.write(it, 21, x.minNlc)
128
        sheet.write(it, 21, x.maxprice)
147
        sheet.write(it, 22, x.maxprice)
129
        sheet.write(it, 22, x.rank)
148
        sheet.write(it, 23, x.rank)
130
        sheet.write(it, 23, x.nlcPoints)
149
        sheet.write(it, 24, x.nlcPoints)
131
        sheet.write(it, 24, x.bestSellerPoints)
150
        sheet.write(it, 25, x.bestSellerPoints)
132
        sheet.write(it, 25, x.catalogBestSellerPoints)
151
        sheet.write(it, 26, x.catalogBestSellerPoints)
133
        sheet.write(it, 26, x.totalPoints)
152
        sheet.write(it, 27, x.totalPoints)
134
        sheet.write(it, 27, x.showDeal)
153
        sheet.write(it, 28, x.showDeal)
-
 
154
        sheet.write(it, 28, x.showDealOld)
135
        it+=1
155
        it+=1
136
    filename = "/tmp/deal-data"+str(datetime.now())+".xls" 
156
    filename = "/tmp/deal-data"+str(datetime.now())+".xls" 
137
    wbk.save(filename)
157
    wbk.save(filename)
138
    smtpServer = smtplib.SMTP('localhost')
158
    smtpServer = smtplib.SMTP('localhost')
139
    #smtpServer.set_debuglevel(1)
159
    #smtpServer.set_debuglevel(1)