Rev 224 | Blame | Compare with Previous | Last modification | View Log | RSS feed
'''Created on 01-Jun-2010@author: gaurav'''from datastore.DataAccessor import DataHelperimport sysfrom StdFormatConv.SplitBrandandModel import *from StdFormatConv.RefineModel import *import os'''Get all the naaptol phones first.Postprocess the phones and brake the phone name column intobrand and model name respectively'''ds = os.sepda = DataHelper()da.initxy()site = "www.naaptol.com"onsp = da.get_allntonlinesp()if not onsp:print "Error while getting onlinesuppliers"sys.exit(-1)for sp in onsp:da.add_supplier(sp.name, site)offsp = da.get_allntofflinesp()if not offsp:print "Error while getting offlinesuppliers"sys.exit(-1)for sp in offsp:da.add_supplier(sp.name, site)phones = da.get_allnaaptolphones()if not phones:print "Error while getting phones"sys.exit(-1)file_to_write = ds+"tmp"+ds+"filterednaaptol.csv"data_file = open(file_to_write,"w")csv_data = "%s, %s, %s, %s, %s, %s, %s" %("brand", "model", "shown_price", "final_price", "extra_info", "supplier_name", "mode of selling")data_file.write(csv_data)data_file.write("\n")for phone in phones:unparsed_name = phone.nameunparsed_name = getunformatted(unparsed_name)vendor_name, phone_name,e_info = getbrandandmodel(unparsed_name)if vendor_name == "":vendor_name = "unknown"model_name,extra_info = getrefinedmodel(phone_name)extra_info = e_info + extra_infoif extra_info.endswith(','):extra_info = extra_info[0:len(extra_info)-1]da.add_models(vendor_name, model_name)modId = da.get_modId(vendor_name,model_name)sups = da.get_ntofflinespbynid(phone.id)for sup in sups:sup_name = sup.namefinal_price = quoted_price = sup.pricesupId = da.get_suppId(sup_name)da.add_prices(modId, supId,quoted_price,final_price,extra_info)csv_data = "%s, %s, %d, %d, %s, %s, %s" %(vendor_name, model_name, quoted_price, final_price,extra_info,sup_name, "offline")data_file.write(csv_data)data_file.write("\n")sups = da.get_ntonlinespbynid(phone.id)for sup in sups:sup_name = sup.namefinal_price = quoted_price = sup.pricesupId = da.get_suppId(sup_name)da.add_prices(modId, supId,quoted_price,final_price,extra_info)csv_data = "%s, %s, %d, %d, %s, %s, %s" %(vendor_name, model_name, quoted_price, final_price,extra_info,sup_name, "online")data_file.write(csv_data)data_file.write("\n")data_file.close()