Subversion Repositories SmartDukaan

Rev

Rev 175 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
175 ashish 1
'''
2
Created on 01-Jun-2010
3
 
4
@author: gaurav
5
'''
6
 
7
from datastore.DataAccessor import DataHelper
8
import sys
9
from StdFormatConv.SplitBrandandModel import *
10
from StdFormatConv.RefineModel import *
11
 
12
'''
13
Get all the naaptol phones first.
14
Postprocess the phones and brake the phone name column into 
15
brand and model name respectively
16
'''
17
 
18
da = DataHelper()
224 ashish 19
da.initxy()
175 ashish 20
 
224 ashish 21
site = "www.naaptol.com"
175 ashish 22
 
23
onsp = da.get_allntonlinesp()
24
if not onsp:
25
    print "Error while getting onlinesuppliers"
26
    sys.exit(-1)
27
for sp in onsp:
28
    da.add_supplier(sp.name, site)
29
 
30
 
31
offsp = da.get_allntofflinesp()    
32
if not offsp:
33
    print "Error while getting offlinesuppliers"
34
    sys.exit(-1)
35
for sp in offsp:
36
    da.add_supplier(sp.name, site)
37
 
38
 
39
 
40
phones = da.get_allnaaptolphones()
41
 
42
if not phones:
43
    print "Error while getting phones"
44
    sys.exit(-1)
45
 
224 ashish 46
file_to_write = "/home/gaurav/filterednaaptol.csv"
175 ashish 47
 
48
data_file = open(file_to_write,"w")
224 ashish 49
csv_data =  "%s, %s, %s, %s, %s, %s, %s" %("brand", "model", "shown_price", "final_price", "extra_info", "supplier_name", "mode of selling")
50
data_file.write(csv_data)
51
data_file.write("\n")
175 ashish 52
 
53
 
54
for phone in phones:
224 ashish 55
    unparsed_name = phone.name
56
    unparsed_name = getunformatted(unparsed_name)
175 ashish 57
    vendor_name, phone_name,e_info = getbrandandmodel(unparsed_name)
58
    if vendor_name == "":
59
        vendor_name = "unknown"
60
    model_name,extra_info = getrefinedmodel(phone_name)   
61
    extra_info = e_info + extra_info
62
    if extra_info.endswith(','):
63
        extra_info = extra_info[0:len(extra_info)-1]
64
 
65
    da.add_models(vendor_name, model_name)          
66
 
67
    modId = da.get_modId(vendor_name,model_name)
68
    sups = da.get_ntofflinespbynid(phone.id)
69
    for sup in sups:    
70
        sup_name = sup.name
71
        final_price = quoted_price = sup.price 
224 ashish 72
 
175 ashish 73
        supId = da.get_suppId(sup_name)
74
        da.add_prices(modId, supId,quoted_price,final_price,extra_info)
224 ashish 75
        csv_data =  "%s, %s, %d, %d, %s, %s, %s" %(vendor_name, model_name, quoted_price, final_price,extra_info,sup_name, "offline")
76
        print "%s, %s, %d, %d, %s %s" %(vendor_name, model_name, quoted_price, final_price,extra_info, sup_name)
175 ashish 77
        data_file.write(csv_data)
78
        data_file.write("\n")
79
 
224 ashish 80
    sups = da.get_ntonlinespbynid(phone.id)
175 ashish 81
    for sup in sups:    
82
        sup_name = sup.name
83
        final_price = quoted_price = sup.price 
84
        supId = da.get_suppId(sup_name)
85
        da.add_prices(modId, supId,quoted_price,final_price,extra_info)
224 ashish 86
        csv_data =  "%s, %s, %d, %d, %s, %s, %s" %(vendor_name, model_name, quoted_price, final_price,extra_info,sup_name, "online")
87
        print "%s, %s, %d, %d, %s %s" %(vendor_name, model_name, quoted_price, final_price,extra_info, sup_name)
175 ashish 88
        data_file.write(csv_data)
89
        data_file.write("\n")
90
 
91
data_file.close()
92