Subversion Repositories SmartDukaan

Rev

Rev 238 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 238 Rev 264
Line 4... Line 4...
4
@author: gaurav
4
@author: gaurav
5
'''
5
'''
6
 
6
 
7
from elixir import *
7
from elixir import *
8
 
8
 
9
#flag = False
-
 
10
 
9
'''
11
class PhoneItem(Entity):
10
class PhoneItem(Entity):
12
    url = Field(String(1000))
11
    url = Field(String(1000))
13
    name = Field(String(50))
12
    name = Field(String(50))
14
    price = Field(Integer)
13
    price = Field(Integer)
15
    source = Field(String(100))
14
    source = Field(String(100))
Line 26... Line 25...
26
   
25
   
27
class Vendor(Entity):
26
class Vendor(Entity):
28
    v_name = Field(String(100))
27
    v_name = Field(String(100))
29
    v_url = Field(String(1000))
28
    v_url = Field(String(1000))
30
 
29
 
-
 
30
class themobilestoreurls(Entity):
-
 
31
    url = Field(String(1000))
-
 
32
    
-
 
33
class themobilestorephones(Entity):
-
 
34
    name = Field(String(100))
-
 
35
    shown_price = Field(Integer)
-
 
36
    final_price = Field(Integer)
-
 
37
 
-
 
38
class pricesbolourls(Entity):
-
 
39
    url = Field(String(1000))
-
 
40
    
-
 
41
class pricesbolophones(Entity):
-
 
42
    name = Field(String(100))
-
 
43
    shown_price = Field(Integer)
-
 
44
    final_price = Field(Integer)
-
 
45
'''
-
 
46
 
-
 
47
"""
-
 
48
For each class crawl_id is used to retain past data for comparison, on each new crawl a new crawl_id is generated
-
 
49
"""
-
 
50
class crawl(Entity):
-
 
51
    """
-
 
52
    Documentation for class crawl
-
 
53
    It represents database table for crawl, it stores
-
 
54
    crawled_date = date of crawling
-
 
55
    On each new crawl a new entry is made
-
 
56
    Reason for creating this table is for retaining past data for comparison
-
 
57
    """
-
 
58
    crawled_date = Field(DATE(100))
-
 
59
 
31
class infibeam_data(Entity):
60
class infibeam_data(Entity):
-
 
61
    """
-
 
62
    Documentation for class infibeam_data
-
 
63
    It represents database table for infibeam, it stores
-
 
64
    name = name of the phone
-
 
65
    shown_price = price offered by infibeam
-
 
66
    final_price = price which one has to pay, 
-
 
67
    final_price = shown_price + taxes + ship-price
-
 
68
    """
-
 
69
    crawl_id = Field(Integer)
32
    name = Field(String(100))
70
    name = Field(String(100))
33
    shown_price = Field(Integer)
71
    shown_price = Field(Integer)
34
    final_price = Field(Integer)
72
    final_price = Field(Integer)
35
 
73
 
36
class univercell_data(Entity):    
74
class univercell_data(Entity):    
-
 
75
    """
-
 
76
    Documentation for class univercell_data
-
 
77
    It represents database table for univercell, it stores
-
 
78
    v_name = name of the vendor
-
 
79
    v_site = url of the vendor
-
 
80
    """
-
 
81
    crawl_id = Field(Integer)
37
    v_name = Field(String(100))
82
    v_name = Field(String(100))
38
    v_site = Field(String(1000))
83
    v_site = Field(String(1000))
39
    
84
    
40
class univercell_items(Entity):    
85
class univercell_items(Entity):
-
 
86
    """
-
 
87
    Documentation for class univercell_items
-
 
88
    It represents database table for univercell, it stores
-
 
89
    p_title = name of the phone
-
 
90
    p_shown_price = price offered by univercell
-
 
91
    p_final_price = price which one has to pay, 
-
 
92
    p_final_price = p_shown_price + taxes + ship-price
-
 
93
    """    
-
 
94
    crawl_id = Field(Integer)
41
    p_title = Field(String(100))
95
    p_title = Field(String(100))
42
    p_shown_price = Field(Integer)
96
    p_shown_price = Field(Integer)
43
    p_final_price = Field(Integer)
97
    p_final_price = Field(Integer)
44
 
98
 
45
class indiaplaza_data(Entity):    
99
class indiaplaza_data(Entity):
-
 
100
    """
-
 
101
    Documentation for class indiaplaza_data
-
 
102
    It represents database table for indiaplaza, it stores
-
 
103
    v_name = name of the vendor
-
 
104
    v_site = url of the vendor
-
 
105
    """
-
 
106
    crawl_id = Field(Integer)    
46
    v_name = Field(String(100))
107
    v_name = Field(String(100))
47
    v_site = Field(String(1000))
108
    v_site = Field(String(1000))
48
    
109
    
49
class indiaplaza_items(Entity): 
110
class indiaplaza_items(Entity): 
-
 
111
    """
-
 
112
    Documentation for class indiaplaza_items
-
 
113
    It represents database table for indiaplaza, it stores
-
 
114
    p_name = name of the phone
-
 
115
    p_shown_price = price offered by indiaplaza
-
 
116
    p_final_price = price which one has to pay, 
-
 
117
    p_final_price = p_shown_price + taxes + ship-price
-
 
118
    p_guaranteeinfo = duaration of guarantee and whether guarantee is from vendor or manufacturer 
-
 
119
    p_shipinfo = how much time would be taken for shipping
-
 
120
    """
-
 
121
    crawl_id = Field(Integer)
50
    p_name = Field(String(100))   
122
    p_name = Field(String(100))   
51
    p_shown_price = Field(Integer)
123
    p_shown_price = Field(Integer)
52
    p_final_price = Field(Integer)
124
    p_final_price = Field(Integer)
53
    p_guaranteeinfo = Field(String(100))
125
    p_guaranteeinfo = Field(String(100))
54
    p_shipinfo = Field(String(100))
126
    p_shipinfo = Field(String(100))
55
    
127
    
56
class themobilestoreurls(Entity):
-
 
57
    url = Field(String(1000))
-
 
58
    
-
 
59
class themobilestorephones(Entity):
-
 
60
    name = Field(String(100))
-
 
61
    shown_price = Field(Integer)
-
 
62
    final_price = Field(Integer)
-
 
63
 
128
 
64
class themobilestorephones_new(Entity):
129
class themobilestorephones_new(Entity):
-
 
130
    """
-
 
131
    Documentation for class themobilestorephones_new
-
 
132
    It represents database table for themobilestore, it stores
-
 
133
    name = name of the phone
-
 
134
    shown_price = price offered by themobilestore
-
 
135
    final_price = price which one has to pay, 
-
 
136
    final_price = shown_price + taxes + ship-price
-
 
137
    extra_info = whether phone can be bought or not
-
 
138
    """
-
 
139
    crawl_id = Field(Integer)
65
    name = Field(String(100))
140
    name = Field(String(100))
66
    shown_price = Field(Integer)
141
    shown_price = Field(Integer)
67
    final_price = Field(Integer)
142
    final_price = Field(Integer)
68
    extra_info = Field(String(1000))
143
    extra_info = Field(String(1000))
69
 
144
 
70
                 
-
 
71
class extra_vars(Entity):
-
 
72
    var = Field(String(100))    
-
 
73
    val = Field(String(100))
-
 
74
    desc = Field(String(1000))
-
 
75
    
-
 
76
class pricesbolourls(Entity):
-
 
77
    url = Field(String(1000))
-
 
78
    
-
 
79
class pricesbolophones(Entity):
-
 
80
    name = Field(String(100))
-
 
81
    shown_price = Field(Integer)
-
 
82
    final_price = Field(Integer)
-
 
83
 
-
 
84
class naaptolurls(Entity):
145
class naaptolurls(Entity):
-
 
146
    """
-
 
147
    Documentation for class naaptolurls
-
 
148
    It represents database table for naaptol, it stores
-
 
149
    url = url of the phones, which we got from sitemap.xml
-
 
150
    """    
-
 
151
    crawl_id = Field(Integer)
85
    url = Field(String(1000))   
152
    url = Field(String(1000))   
86
 
153
 
87
class morenaaptolurls(Entity):
154
class morenaaptolurls(Entity):
-
 
155
    """
-
 
156
    Documentation for class naaptolurls
-
 
157
    It represents database table for naaptol, it stores
-
 
158
    url = url of the phones, here urls are the ones which are redirected 
-
 
159
    and contained 'price' but before storing 'price' is replaced by 'features'
-
 
160
    """
-
 
161
    crawl_id = Field(Integer)
88
    url = Field(String(1000)) 
162
    url = Field(String(1000)) 
89
    
163
    
90
class naaptolphones(Entity):      
164
class naaptolphones(Entity):
-
 
165
    """
-
 
166
    Documentation for class naaptolphones
-
 
167
    It represents database table for naaptol, it stores
-
 
168
    name = name of the phone, 
-
 
169
    range = price range for each phone
-
 
170
    range is in one of the 3 forms, i.e
-
 
171
    range = a to b
-
 
172
    range = a
-
 
173
    range = a(approx)
-
 
174
    here a,b are integers
-
 
175
    """      
-
 
176
    crawl_id = Field(Integer)
91
    name = Field(String(100))
177
    name = Field(String(100))
92
    range = Field(String(100))
178
    range = Field(String(100))
93
    
179
    
94
class ntonlinesp(Entity):
180
class ntonlinesp(Entity):
-
 
181
    """
-
 
182
    Documentation for class ntonlinesp
-
 
183
    It represents database table for naaptol, it stores
-
 
184
    nid = id of the phone in naaptolphones 
-
 
185
    name = name of the onlinesupplier, 
-
 
186
    price = price offered by the supplier for the phone 
-
 
187
    """
-
 
188
    crawl_id = Field(Integer)
95
    nid = Field(Integer)
189
    nid = Field(Integer)
96
    name = Field(String(100))
190
    name = Field(String(100))
97
    price = Field(Integer)
191
    price = Field(Integer)
98
    
192
    
99
class ntofflinesp(Entity):
193
class ntofflinesp(Entity):
-
 
194
    """
-
 
195
    Documentation for class ntofflinesp
-
 
196
    It represents database table for naaptol, it stores
-
 
197
    nid = id of the phone in naaptolphones 
-
 
198
    name = name of the offlinesupplier, 
-
 
199
    price = price offered by the supplier for the phone 
-
 
200
    """
-
 
201
    crawl_id = Field(Integer)
100
    nid = Field(Integer)
202
    nid = Field(Integer)
101
    name = Field(String(100))
203
    name = Field(String(100))
102
    price = Field(Integer)
204
    price = Field(Integer)
103
 
205
 
104
class babuchak_urls(Entity):
206
class babuchak_urls(Entity):
-
 
207
    """
-
 
208
    Documentation for class babuchak_urls
-
 
209
    It represents database table for babuchak, it stores
-
 
210
    url = url for the vendors
-
 
211
    no_pages = number of pages for individual vendor
-
 
212
    """
-
 
213
    crawl_id = Field(Integer)
105
    url = Field(String(100))
214
    url = Field(String(100))
106
    no_pages = Field(Integer)
215
    no_pages = Field(Integer)
107
            
216
            
108
class babuchak_phoneurls(Entity):
217
class babuchak_phoneurls(Entity):
-
 
218
    """
-
 
219
    Documentation for class babuchak_phoneurls
-
 
220
    It represents database table for babuchak, it stores
-
 
221
    url = url for the individual phones
-
 
222
    """
-
 
223
    crawl_id = Field(Integer)
109
    url = Field(String(100))
224
    url = Field(String(100))
110
    
225
    
111
class babuchak_phones(Entity):
226
class babuchak_phones(Entity):
-
 
227
    """
-
 
228
    Documentation for class babuchak_phones
-
 
229
    It represents database table for babuchak, it stores
-
 
230
    name = name of the phone
-
 
231
    shown_price = price offered by babuchak
-
 
232
    final_price = price which one has to pay, 
-
 
233
    final_price = shown_price + taxes + ship-price
-
 
234
    """
-
 
235
    crawl_id = Field(Integer)
112
    name = Field(String(100))
236
    name = Field(String(100))
113
    shown_price = Field(Integer)
237
    shown_price = Field(Integer)
114
    final_price = Field(Integer)
238
    final_price = Field(Integer)
115
                
239
                
116
class suppliers(Entity):
240
class suppliers(Entity):
-
 
241
    """
-
 
242
    Documentation for class suppliers
-
 
243
    It represents database table for suppliers, it stores
-
 
244
    name = name of the supplier
-
 
245
    site = url of the supplier
-
 
246
    last_crawled = date of the last run for this supplier
-
 
247
    This table spans all the suppliers in our database
-
 
248
    """
117
    name = Field(String(100))
249
    name = Field(String(100))
118
    site = Field(String(100))
250
    site = Field(String(100))
119
    last_crawled = Field(DATE(100))
251
    last_crawled = Field(DATE(100))
120
    
252
    
121
class models(Entity):
253
class models(Entity):
-
 
254
    """
-
 
255
    Documentation for class models
-
 
256
    It represents database table for models, it stores
-
 
257
    brand = name of the brand for a particular phone
-
 
258
    model = name of the model for a particular phone
-
 
259
    This table spans all the phones-models in our database
-
 
260
    """
-
 
261
    crawl_id = Field(Integer)
122
    brand = Field(String(100))
262
    brand = Field(String(100))
123
    model = Field(String(100))
263
    model = Field(String(100))
124
    
264
    
125
class guarantee_info(Entity):
-
 
126
    mid = Field(Integer)
-
 
127
    guaranteeinfo = Field(String(100))
-
 
128
    shipinfo = Field(String(100))
-
 
129
    
-
 
130
  
-
 
131
class prices(Entity):
265
class prices(Entity):
-
 
266
    """
-
 
267
    Documentation for class prices
-
 
268
    It represents database table for prices, it stores
-
 
269
    supplier_id = id of the supplier who is selling this phone, from suppliers table
-
 
270
    mobile_id = id of the model of this phone, from models table
-
 
271
    quoted_price = price of the phone as offered by the supplier 
-
 
272
    final_price = price one has to pay to buy this phone, i.e
-
 
273
    it includes vat, tax and shippping charges
-
 
274
    extra_info = extra-info about this phone
-
 
275
    This table spans all the phones in our database
-
 
276
    """
-
 
277
    crawl_id = Field(Integer)
132
    supplier_id = Field(Integer)
278
    supplier_id = Field(Integer)
133
    mobile_id = Field(Integer)
279
    mobile_id = Field(Integer)
134
    quoted_price = Field(Integer)  
280
    quoted_price = Field(Integer)  
135
    final_price = Field(Integer)
281
    final_price = Field(Integer)
136
    extra_info = Field(String(1000))
282
    extra_info = Field(String(1000))
137
    
283
    
-
 
284
class guarantee_info(Entity):
-
 
285
    """
-
 
286
    Documentation for class guarantee_info
-
 
287
    It represents database table for guarantee_info, it stores
-
 
288
    mid = id of the phone in models table
-
 
289
    guaranteeinfo = duaration of guarantee and whether guarantee is from vendor or manufacturer 
-
 
290
    shipinfo = how much time would be taken for shipping.
-
 
291
    This table spans all the phones in our database
-
 
292
    """
-
 
293
    crawl_id = Field(Integer)
-
 
294
    mid = Field(Integer)
-
 
295
    guaranteeinfo = Field(String(100))
-
 
296
    shipinfo = Field(String(100))
138
        
297
        
-
 
298
class extra_vars(Entity):
-
 
299
    """
-
 
300
    Documentation for class extra_vars
-
 
301
    It represents database table for extra_vars, it stores
-
 
302
    var = name of the variable
-
 
303
    val = value of the variable
-
 
304
    desc = description of the variable
-
 
305
    For some suppliers the number of pages to be crawled is not fixed,
-
 
306
    for them variables are created and based on the value of the variable 
-
 
307
    number of the pages to be crawled is determined dynamically
-
 
308
    """
-
 
309
    var = Field(String(100))    
-
 
310
    val = Field(String(100))
-
 
311
    desc = Field(String(1000))
-
 
312
 
139
def init():
313
def init():
-
 
314
    """
-
 
315
    Documentation for method init
-
 
316
    Before using all the tables described in this module, one has to call this method
-
 
317
    """
140
    #metadata.bind = "sqlite:///phones.sqlite"
318
    #metadata.bind = "sqlite:///phones.sqlite"
141
    metadata.bind = "mysql://root@localhost/phonecrawler"
319
    metadata.bind = "mysql://root@localhost/phonecrawler"
142
    metadata.bind.echo = True
320
    metadata.bind.echo = True
143
    setup_all(True)
321
    setup_all(True)
144
    pass
322
    pass