Subversion Repositories SmartDukaan

Rev

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

Rev 5401 Rev 5413
Line 259... Line 259...
259
 
259
 
260
class DownloadHandler(BaseHandler):
260
class DownloadHandler(BaseHandler):
261
    
261
    
262
    def post(self):
262
    def post(self):
263
        catalog_client = CatalogClient().get_client()
263
        catalog_client = CatalogClient().get_client()
-
 
264
        retriever = Retriever()
264
        vendors = {}
265
        vendors = {}
265
        
266
        
266
        for vendor in catalog_client.getAllVendors():
267
        for vendor in catalog_client.getAllVendors():
267
            vendors[vendor.id] = vendor.name
268
            vendors[vendor.id] = vendor.name
268
        
269
        
269
        self.set_header('Content-Type', 'text/csv')
270
        self.set_header('Content-Type', 'text/csv')
-
 
271
        self.set_header("Content-disposition", "inline; filename=price-comparison.xls")
270
        
272
 
271
        newLine = '\n'
273
        newLine = '\n'
272
        tab = '\t'
274
        tab = '\t'
273
 
275
 
274
        header = 'Product' + tab
276
        header = 'Product' + tab
275
        header += 'Vendor' + tab + 'Transfer Price' + tab + 'Vendor' + tab + 'Transfer Price' + tab +  'Vendor' + tab + 'Transfer Price' + tab
277
        header += 'Vendor' + tab + 'TP' + tab + 'Vendor' + tab + 'TP' + tab +  'Vendor' + tab + 'TP' + tab
276
        header += 'Saholic' + newLine
278
        header += 'Saholic' + tab + 'Flipkart' + tab + 'Homeshop18' + tab + 'Infibeam' + tab +  'Snapdeal' + newLine
277
        
279
        
278
        responseText = header
280
        responseText = header
279
        
281
        
280
        for item in getValidItems():
282
        for item in getValidItems():
281
            vendorItemPricings = catalog_client.getAllItemPricing(item.id)
283
            vendorItemPricings = catalog_client.getAllItemPricing(item.id)
282
            sortedPricings = sorted(vendorItemPricings, key = lambda vendorItemPricing: vendorItemPricing.transferPrice)
284
            sortedPricings = sorted(vendorItemPricings, key = lambda vendorItemPricing: vendorItemPricing.transferPrice)
-
 
285
            productName = getProductName(item)
283
            
286
            
284
            row = getProductName(item) + tab
287
            row = productName + tab
285
            
288
            
286
            if len(sortedPricings) > 0:
289
            if len(sortedPricings) > 0:
287
                row += vendors[sortedPricings[0].vendorId] + tab + str(sortedPricings[0].transferPrice) + tab
290
                row += vendors[sortedPricings[0].vendorId] + tab + str(sortedPricings[0].transferPrice) + tab
288
            else:
291
            else:
289
                row += tab + tab
292
                row += tab + tab
Line 296... Line 299...
296
            if len(sortedPricings) > 2:
299
            if len(sortedPricings) > 2:
297
                row += vendors[sortedPricings[2].vendorId] + tab + str(sortedPricings[2].transferPrice) + tab
300
                row += vendors[sortedPricings[2].vendorId] + tab + str(sortedPricings[2].transferPrice) + tab
298
            else:
301
            else:
299
                row += tab + tab
302
                row += tab + tab
300
            
303
            
301
            row += str(item.sellingPrice) + newLine
304
            row += str(item.sellingPrice) + tab
-
 
305
            
-
 
306
            model_name = item.modelName.strip() if len(item.modelName.strip()) > 0 else None
-
 
307
            model_number = item.modelNumber.strip() if len(item.modelNumber.strip()) > 0 else None
-
 
308
            
-
 
309
            search_results = retriever.retrieve(model_number = model_number, model_name = model_name, brand = item.brand, synonyms = None)
-
 
310
            
-
 
311
            clusters = getProductClusters(search_results)
-
 
312
            filtered_clusters = getFilteredClustersWithTopScores(clusters)
-
 
313
            display_info = getDisplayInfo(filtered_clusters, productName)
-
 
314
            
-
 
315
            if 'price' in display_info['flipkart'] and display_info['flipkart']['price'] is not None:
-
 
316
                row += display_info['flipkart']['price'] + tab
-
 
317
            else:
-
 
318
                row += tab
-
 
319
            
-
 
320
            if 'price' in display_info['homeshop18'] and display_info['homeshop18']['price'] is not None:
-
 
321
                row += display_info['homeshop18']['price'] + tab
-
 
322
            else:
-
 
323
                row += tab
302
            
324
            
-
 
325
            if 'price' in display_info['infibeam'] and display_info['infibeam']['price'] is not None:
-
 
326
                row += display_info['infibeam']['price'] + tab
-
 
327
            else:
-
 
328
                row += tab
-
 
329
            
-
 
330
            if 'price' in display_info['snapdeal'] and display_info['snapdeal']['price'] is not None:
-
 
331
                row += display_info['snapdeal']['price'] + tab
-
 
332
            else:
-
 
333
                row += tab
303
            responseText += row
334
            responseText += row + newLine
304
        
335
        
305
        self.write(responseText)
336
        self.write(responseText)
306
    
337
    
307
settings  = {
338
settings  = {
308
        'static_path': os.path.join(os.path.dirname(__file__), 'static'),
339
        'static_path': os.path.join(os.path.dirname(__file__), 'static'),
Line 321... Line 352...
321
            ], **settings)
352
            ], **settings)
322
 
353
 
323
if __name__ == '__main__':
354
if __name__ == '__main__':
324
    http_server = tornado.httpserver.HTTPServer(application)
355
    http_server = tornado.httpserver.HTTPServer(application)
325
    http_server.listen(8889)
356
    http_server.listen(8889)
326
    tornado.ioloop.IOLoop.instance().start()
-
 
327
357
    tornado.ioloop.IOLoop.instance().start()
-
 
358