Rev 224 | Go to most recent revision | 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 *'''Get all the naaptol phones first.Postprocess the phones and brake the phone name column intobrand and model name respectively'''site = "www.naaptol.com"da = DataHelper()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 = "/tmp/filterednaaptol.csv"data_file = open(file_to_write,"w")for phone in phones:unparsed_name = getunformatted(phone.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)#print "unparsed_name : " + unparsed_name#print "vendor_name : " + vendor_name#print "phone_name : " + phone_name#print unparsed_namemodId = 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" %(vendor_name, model_name, quoted_price, final_price,extra_info)data_file.write(csv_data)data_file.write("\n")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" %(vendor_name, model_name, quoted_price, final_price,extra_info)data_file.write(csv_data)data_file.write("\n")data_file.close()