Subversion Repositories SmartDukaan

Rev

Rev 224 | 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 *
254 ashish 11
import os
175 ashish 12
 
13
'''
14
Get all the naaptol phones first.
15
Postprocess the phones and brake the phone name column into 
16
brand and model name respectively
17
'''
254 ashish 18
ds = os.sep
175 ashish 19
da = DataHelper()
224 ashish 20
da.initxy()
175 ashish 21
 
224 ashish 22
site = "www.naaptol.com"
175 ashish 23
 
24
onsp = da.get_allntonlinesp()
25
if not onsp:
26
    print "Error while getting onlinesuppliers"
27
    sys.exit(-1)
28
for sp in onsp:
29
    da.add_supplier(sp.name, site)
30
 
31
 
32
offsp = da.get_allntofflinesp()    
33
if not offsp:
34
    print "Error while getting offlinesuppliers"
35
    sys.exit(-1)
36
for sp in offsp:
37
    da.add_supplier(sp.name, site)
38
 
39
 
40
 
41
phones = da.get_allnaaptolphones()
42
 
43
if not phones:
44
    print "Error while getting phones"
45
    sys.exit(-1)
46
 
254 ashish 47
file_to_write = ds+"tmp"+ds+"filterednaaptol.csv"
175 ashish 48
 
49
data_file = open(file_to_write,"w")
224 ashish 50
csv_data =  "%s, %s, %s, %s, %s, %s, %s" %("brand", "model", "shown_price", "final_price", "extra_info", "supplier_name", "mode of selling")
51
data_file.write(csv_data)
52
data_file.write("\n")
175 ashish 53
 
54
 
55
for phone in phones:
224 ashish 56
    unparsed_name = phone.name
57
    unparsed_name = getunformatted(unparsed_name)
175 ashish 58
    vendor_name, phone_name,e_info = getbrandandmodel(unparsed_name)
59
    if vendor_name == "":
60
        vendor_name = "unknown"
61
    model_name,extra_info = getrefinedmodel(phone_name)   
62
    extra_info = e_info + extra_info
63
    if extra_info.endswith(','):
64
        extra_info = extra_info[0:len(extra_info)-1]
65
 
66
    da.add_models(vendor_name, model_name)          
67
 
68
    modId = da.get_modId(vendor_name,model_name)
69
    sups = da.get_ntofflinespbynid(phone.id)
70
    for sup in sups:    
71
        sup_name = sup.name
72
        final_price = quoted_price = sup.price 
224 ashish 73
 
175 ashish 74
        supId = da.get_suppId(sup_name)
75
        da.add_prices(modId, supId,quoted_price,final_price,extra_info)
224 ashish 76
        csv_data =  "%s, %s, %d, %d, %s, %s, %s" %(vendor_name, model_name, quoted_price, final_price,extra_info,sup_name, "offline")
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")
175 ashish 87
        data_file.write(csv_data)
88
        data_file.write("\n")
89
 
90
data_file.close()
91