Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
13828 kshitij.so 1
import pymongo
2
import xlwt
3
 
4
p = []
5
con = None
6
 
7
class __SkuInfo:
8
 
9
    def __init__(self, _id, skuBundleId, category_id, mrp, available_price, source_id, rank, maxNlc, minNlc, schemeAmount, minDiscount, \
10
                 maxDiscount, discountType, dp, nlcPoints, bestSellerPoints, totalPoints,in_stock,maxprice,showDeal):
11
        self._id = _id
12
        self.skuBundleId = skuBundleId
13
        self.category_id = category_id
14
        self.mrp = mrp
15
        self.available_price = available_price
16
        self.source_id = source_id
17
        self.rank = rank
18
        self.maxNlc = maxNlc
19
        self.minNlc = minNlc
20
        self.schemeAmount = schemeAmount
21
        self.minDiscount = minDiscount
22
        self.maxDiscount = maxDiscount
23
        self.discountType = discountType
24
        self.dp = dp
25
        self.nlcPoints = nlcPoints
26
        self.bestSellerPoints = bestSellerPoints
27
        self.totalPoints = totalPoints
28
        self.in_stock = in_stock
29
        self.maxprice = maxprice
30
        self.showDeal = showDeal 
31
 
32
def get_mongo_connection(host='localhost', port=27017):
33
    global con
34
    if con is None:
35
        print "Establishing connection %s host and port %d" %(host,port)
36
        try:
37
            con = pymongo.MongoClient(host, port)
38
        except Exception, e:
39
            print e
40
            return None
41
    return con
42
 
43
 
44
def getProducts():
45
    global p
46
    data = get_mongo_connection().Catalog.Deals.find().sort([('totalPoints',pymongo.DESCENDING)])
47
    print data.count()
48
    for x in data:
49
        s_info = __SkuInfo(x['_id'], x['skuBundleId'], x['category_id'],x['mrp'],x['available_price'],x['source_id'],x['rank'],x['maxNlc'], \
50
                           x['minNlc'], x['schemeAmount'],x['minDiscount'],x['maxDiscount'],x['discountType'],x['dp'],x['nlcPoints'],x['bestSellerPoints'], \
51
                           x['totalPoints'],x['in_stock'],x['maxprice'],x['showDeal'])
52
        p.append(s_info)
53
 
54
def writeSheet():
55
    wbk = xlwt.Workbook()
56
    sheet = wbk.add_sheet('Deals')
57
    xstr = lambda s: s or ""
58
    heading_xf = xlwt.easyxf('font: bold on; align: wrap off, vert centre, horiz center')
59
 
60
    excel_integer_format = '0'
61
    integer_style = xlwt.XFStyle()
62
    integer_style.num_format_str = excel_integer_format
63
 
64
    sheet.write(0, 0, "Item ID", heading_xf)
65
    sheet.write(0, 1, "Catalog Item Id", heading_xf)
66
    sheet.write(0, 2, "Category", heading_xf)
67
    sheet.write(0, 3, "Brand", heading_xf)
68
    sheet.write(0, 4, "Product Name", heading_xf)
69
    sheet.write(0, 5, "Item Status", heading_xf)
70
    sheet.write(0, 6, "Stock Status", heading_xf)
71
    sheet.write(0, 7, "MarketPlace", heading_xf)
72
    sheet.write(0, 8, "MarketPlace Identifier", heading_xf)
73
    sheet.write(0, 9, "MarketPlace Secondary Identifier", heading_xf)
74
    sheet.write(0, 10, "Product Name (Marketplace)", heading_xf)
75
    sheet.write(0, 11, "Url", heading_xf)
76
    sheet.write(0, 12, "Price", heading_xf)
77
    sheet.write(0, 13, "Mrp", heading_xf)
78
    sheet.write(0, 14, "DP", heading_xf)
79
    sheet.write(0, 15, "Scheme Amount", heading_xf)
80
    sheet.write(0, 16, "Discount Type", heading_xf)
81
    sheet.write(0, 17, "Min Discount", heading_xf)
82
    sheet.write(0, 18, "Max Discount", heading_xf)
83
    sheet.write(0, 19, "Max Nlc", heading_xf)
84
    sheet.write(0, 20, "Min Nlc", heading_xf)
85
    sheet.write(0, 21, "Max Price", heading_xf)
86
    sheet.write(0, 22, "Rank", heading_xf)
87
    sheet.write(0, 23, "Nlc Points", heading_xf)
88
    sheet.write(0, 24, "Best Seller Points", heading_xf)
89
    sheet.write(0, 25, "Total Points", heading_xf)
90
    sheet.write(0, 26, "Show Deals", heading_xf)
91
 
92
    it = 1
93
    for x in p:
94
        y = list(get_mongo_connection().Catalog.MasterData.find({'_id':x._id}))
95
        sheet.write(it, 0, x._id)
96
        sheet.write(it, 1, x.skuBundleId)
97
        if x.category_id == 3:
98
            category = 'Mobiles'
99
        else:
100
            category = 'Tablets'
101
        sheet.write(it, 2, category)
102
        sheet.write(it, 3, y[0]['brand'])
103
        sheet.write(it, 4, y[0]['product_name'])
104
        if y[0]['status'] ==1:
105
            sheet.write(it, 5, 'Active')
106
        else:
107
            sheet.write(it, 5, 'EOL')
108
        if y[0]['in_stock'] ==1:
109
            sheet.write(it, 6, 'In Stock')
110
        else:
111
            sheet.write(it, 6, 'Out Of Stock')
112
        sheet.write(it, 7, y[0]['source'])
113
        sheet.write(it, 8, y[0]['identifier'])
114
        sheet.write(it, 9, y[0]['secondaryIdentifier'])
115
        sheet.write(it, 10, y[0]['source_product_name'])
116
        sheet.write(it, 11, y[0]['url'])
117
        sheet.write(it, 12, y[0]['available_price'])
118
        sheet.write(it, 13, x.mrp)
119
        sheet.write(it, 14, x.dp)
120
        sheet.write(it, 15, x.schemeAmount)
121
        sheet.write(it, 16, x.discountType)
122
        sheet.write(it, 17, x.minDiscount)
123
        sheet.write(it, 18, x.maxDiscount)
124
        sheet.write(it, 19, x.maxNlc)
125
        sheet.write(it, 20, x.minNlc)
126
        sheet.write(it, 21, x.maxprice)
127
        sheet.write(it, 22, x.rank)
128
        sheet.write(it, 23, x.nlcPoints)
129
        sheet.write(it, 24, x.bestSellerPoints)
130
        sheet.write(it, 25, x.totalPoints)
131
        sheet.write(it, 26, x.showDeal)
132
        it+=1
133
    wbk.save("/tmp/deal-data.xls")
134
 
135
def main():
136
    getProducts()
137
    writeSheet()
138
 
139
 
140
if __name__=='__main__':
141
    main()