Blame | Last modification | View Log | RSS feed
import pymongoimport xlwtp = []con = Noneclass __SkuInfo:def __init__(self, _id, skuBundleId, category_id, mrp, available_price, source_id, rank, maxNlc, minNlc, schemeAmount, minDiscount, \maxDiscount, discountType, dp, nlcPoints, bestSellerPoints, totalPoints,in_stock,maxprice,showDeal):self._id = _idself.skuBundleId = skuBundleIdself.category_id = category_idself.mrp = mrpself.available_price = available_priceself.source_id = source_idself.rank = rankself.maxNlc = maxNlcself.minNlc = minNlcself.schemeAmount = schemeAmountself.minDiscount = minDiscountself.maxDiscount = maxDiscountself.discountType = discountTypeself.dp = dpself.nlcPoints = nlcPointsself.bestSellerPoints = bestSellerPointsself.totalPoints = totalPointsself.in_stock = in_stockself.maxprice = maxpriceself.showDeal = showDealdef get_mongo_connection(host='localhost', port=27017):global conif con is None:print "Establishing connection %s host and port %d" %(host,port)try:con = pymongo.MongoClient(host, port)except Exception, e:print ereturn Nonereturn condef getProducts():global pdata = get_mongo_connection().Catalog.Deals.find().sort([('totalPoints',pymongo.DESCENDING)])print data.count()for x in data:s_info = __SkuInfo(x['_id'], x['skuBundleId'], x['category_id'],x['mrp'],x['available_price'],x['source_id'],x['rank'],x['maxNlc'], \x['minNlc'], x['schemeAmount'],x['minDiscount'],x['maxDiscount'],x['discountType'],x['dp'],x['nlcPoints'],x['bestSellerPoints'], \x['totalPoints'],x['in_stock'],x['maxprice'],x['showDeal'])p.append(s_info)def writeSheet():wbk = xlwt.Workbook()sheet = wbk.add_sheet('Deals')xstr = lambda s: s or ""heading_xf = xlwt.easyxf('font: bold on; align: wrap off, vert centre, horiz center')excel_integer_format = '0'integer_style = xlwt.XFStyle()integer_style.num_format_str = excel_integer_formatsheet.write(0, 0, "Item ID", heading_xf)sheet.write(0, 1, "Catalog Item Id", heading_xf)sheet.write(0, 2, "Category", heading_xf)sheet.write(0, 3, "Brand", heading_xf)sheet.write(0, 4, "Product Name", heading_xf)sheet.write(0, 5, "Item Status", heading_xf)sheet.write(0, 6, "Stock Status", heading_xf)sheet.write(0, 7, "MarketPlace", heading_xf)sheet.write(0, 8, "MarketPlace Identifier", heading_xf)sheet.write(0, 9, "MarketPlace Secondary Identifier", heading_xf)sheet.write(0, 10, "Product Name (Marketplace)", heading_xf)sheet.write(0, 11, "Url", heading_xf)sheet.write(0, 12, "Price", heading_xf)sheet.write(0, 13, "Mrp", heading_xf)sheet.write(0, 14, "DP", heading_xf)sheet.write(0, 15, "Scheme Amount", heading_xf)sheet.write(0, 16, "Discount Type", heading_xf)sheet.write(0, 17, "Min Discount", heading_xf)sheet.write(0, 18, "Max Discount", heading_xf)sheet.write(0, 19, "Max Nlc", heading_xf)sheet.write(0, 20, "Min Nlc", heading_xf)sheet.write(0, 21, "Max Price", heading_xf)sheet.write(0, 22, "Rank", heading_xf)sheet.write(0, 23, "Nlc Points", heading_xf)sheet.write(0, 24, "Best Seller Points", heading_xf)sheet.write(0, 25, "Total Points", heading_xf)sheet.write(0, 26, "Show Deals", heading_xf)it = 1for x in p:y = list(get_mongo_connection().Catalog.MasterData.find({'_id':x._id}))sheet.write(it, 0, x._id)sheet.write(it, 1, x.skuBundleId)if x.category_id == 3:category = 'Mobiles'else:category = 'Tablets'sheet.write(it, 2, category)sheet.write(it, 3, y[0]['brand'])sheet.write(it, 4, y[0]['product_name'])if y[0]['status'] ==1:sheet.write(it, 5, 'Active')else:sheet.write(it, 5, 'EOL')if y[0]['in_stock'] ==1:sheet.write(it, 6, 'In Stock')else:sheet.write(it, 6, 'Out Of Stock')sheet.write(it, 7, y[0]['source'])sheet.write(it, 8, y[0]['identifier'])sheet.write(it, 9, y[0]['secondaryIdentifier'])sheet.write(it, 10, y[0]['source_product_name'])sheet.write(it, 11, y[0]['url'])sheet.write(it, 12, y[0]['available_price'])sheet.write(it, 13, x.mrp)sheet.write(it, 14, x.dp)sheet.write(it, 15, x.schemeAmount)sheet.write(it, 16, x.discountType)sheet.write(it, 17, x.minDiscount)sheet.write(it, 18, x.maxDiscount)sheet.write(it, 19, x.maxNlc)sheet.write(it, 20, x.minNlc)sheet.write(it, 21, x.maxprice)sheet.write(it, 22, x.rank)sheet.write(it, 23, x.nlcPoints)sheet.write(it, 24, x.bestSellerPoints)sheet.write(it, 25, x.totalPoints)sheet.write(it, 26, x.showDeal)it+=1wbk.save("/tmp/deal-data.xls")def main():getProducts()writeSheet()if __name__=='__main__':main()