Subversion Repositories SmartDukaan

Rev

Rev 150 | Rev 203 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 150 Rev 173
Line 5... Line 5...
5
'''
5
'''
6
from datastore.DataDefinition import * #Phones, init, PhoneItem
6
from datastore.DataDefinition import * #Phones, init, PhoneItem
7
 
7
 
8
from elixir import *
8
from elixir import *
9
from datastore.DataDefinition import infibeam_data
9
from datastore.DataDefinition import infibeam_data
10
 
10
import datetime
11
 
11
 
12
 
12
 
13
class DataHelper:
13
class DataHelper:
14
    
14
    
15
    def __init__(self):
15
    def __init__(self):
Line 75... Line 75...
75
        ai.p_title = name
75
        ai.p_title = name
76
        ai.p_shown_price = shown_price
76
        ai.p_shown_price = shown_price
77
        ai.p_final_price = final_price
77
        ai.p_final_price = final_price
78
        session.commit()
78
        session.commit()
79
        
79
        
-
 
80
    def add_ipbasic(self,name,site):
-
 
81
        ai = indiaplaza_data()
-
 
82
        ai.v_name = name
-
 
83
        ai.v_site = site
-
 
84
        session.commit()
-
 
85
    
-
 
86
    def add_mobstoreurl(self,url):
-
 
87
        ai = themobilestoreurls()
-
 
88
        ai.url = url
-
 
89
        session.commit()
-
 
90
        
-
 
91
       
-
 
92
    def add_naaptolurl(self,url):
-
 
93
        ai = naaptolurls()
-
 
94
        ai.url = url
-
 
95
        session.commit()
-
 
96
      
-
 
97
    def add_morenaaptolurl(self,url):
-
 
98
        ai = morenaaptolurls()
-
 
99
        ai.url = url
-
 
100
        session.commit()        
-
 
101
        
-
 
102
    def get_allmobstoreurls(self):
-
 
103
        ai = themobilestoreurls.query.all()
-
 
104
        return ai
-
 
105
    
-
 
106
    def get_allnaaptolurls(self):
-
 
107
        ai = naaptolurls.query.all()
-
 
108
        return ai
-
 
109
     
-
 
110
    def get_allmorenaaptolurls(self):
-
 
111
        ai = morenaaptolurls.query.all()
-
 
112
        return ai
-
 
113
    
-
 
114
    def add_new_mobstorephone(self,name,shown_pr,final_pr):
-
 
115
        ai = themobilestorephones()
-
 
116
        ai.name = name
-
 
117
        ai.shown_price = shown_pr
-
 
118
        ai.final_price = final_pr
-
 
119
        session.commit()
-
 
120
        
-
 
121
    def add_new_naaptolphone(self,name,range):
-
 
122
        temp = name.lower()
-
 
123
        if temp.find("null") != -1:
-
 
124
            return
-
 
125
        for n in self.get_allnaaptolphones(): 
-
 
126
            if n.name == name:
-
 
127
                if n.range == range:
-
 
128
                        return                            
-
 
129
        ai = naaptolphones()
-
 
130
        ai.name = name
-
 
131
        ai.range = range
-
 
132
        session.commit()
-
 
133
    
-
 
134
    def add_new_ntonlinesp(self,nid,name,price):
-
 
135
        ai = ntonlinesp()
-
 
136
        ai.nid = nid
-
 
137
        ai.name = name
-
 
138
        ai.price = price
-
 
139
        session.commit()
-
 
140
    
-
 
141
    def add_new_ntofflinesp(self,nid,name,price):
-
 
142
        ai = ntofflinesp()
-
 
143
        ai.nid = nid
-
 
144
        ai.name = name
-
 
145
        ai.price = price
-
 
146
        session.commit()
-
 
147
        
-
 
148
    def get_naaptolphone(self, name, range):
-
 
149
        query = naaptolphones.query.filter_by(name=name)
-
 
150
        query = query.filter_by(range=range)
-
 
151
        return query.one()
-
 
152
        
-
 
153
 
-
 
154
    def get_allmobstorephones(self):
-
 
155
        ai = themobilestorephones.query.all()
-
 
156
        return ai
-
 
157
        
-
 
158
    def get_allnaaptolphones(self):
-
 
159
        ai = naaptolphones.query.all()
-
 
160
        return ai
-
 
161
    
-
 
162
    def get_allntonlinesp(self):
-
 
163
        ai = ntonlinesp.query.all()
-
 
164
        return ai
-
 
165
    
-
 
166
    def get_allntofflinesp(self):
-
 
167
        ai = ntofflinesp.query.all()
-
 
168
        return ai
-
 
169
    
-
 
170
    def get_ntonlinespbynid(self,nid):
-
 
171
        ai = ntonlinesp.query.filter_by(nid=nid)
-
 
172
        return ai
-
 
173
    
-
 
174
    def get_ntofflinespbynid(self,nid):
-
 
175
        ai = ntofflinesp.query.filter_by(nid=nid)
-
 
176
        return ai
-
 
177
    
-
 
178
            
-
 
179
    def get_all_ipbasic(self):
-
 
180
        vi = indiaplaza_data.query.all()
-
 
181
        return vi
-
 
182
        
-
 
183
    def add_ipextra(self,name,shown_price,final_price,guarantee,shipinfo):
-
 
184
        ai = indiaplaza_items()
-
 
185
        ai.p_name = name
-
 
186
        ai.p_shown_price = shown_price
-
 
187
        ai.p_final_price = final_price
-
 
188
        ai.p_guaranteeinfo = guarantee
-
 
189
        ai.p_shipinfo = shipinfo
-
 
190
        session.commit()
-
 
191
        
-
 
192
    def get_all_infibeam_data(self):
-
 
193
        phones = infibeam_data.query.all()
-
 
194
        return phones
-
 
195
    
-
 
196
    
-
 
197
    def get_all_indiaplaza_phones(self):
-
 
198
        phones = indiaplaza_items.query.all()
-
 
199
        return phones
80
                    
200
                    
81
                    
-
 
82
201
    def get_all_univercell_phones(self):
-
 
202
        phones = univercell_items.query.all()
-
 
203
        return phones
-
 
204
    
-
 
205
    def get_infibeam_csv(self):
-
 
206
        phones = self.get_all_infibeam_phones()
-
 
207
        print phones
-
 
208
    
-
 
209
    def get_all_suppliers(self):
-
 
210
        sup = suppliers.query.all()
-
 
211
        return sup
-
 
212
    
-
 
213
    def get_all_models(self):
-
 
214
        mod = models.query.all()
-
 
215
        return mod
-
 
216
    
-
 
217
    def get_all_prices(self):
-
 
218
        pr = prices.query.all()
-
 
219
        return pr
-
 
220
    
-
 
221
    def get_suppId(self,name):
-
 
222
        for s in self.get_all_suppliers():
-
 
223
            if s.name == name:
-
 
224
                return s.id
-
 
225
    
-
 
226
    def get_supp_byId(self,id):
-
 
227
        for s in self.get_all_suppliers():
-
 
228
            if s.id == id:
-
 
229
                return s
-
 
230
    
-
 
231
    def get_supp_byName(self,name):
-
 
232
        supps = []
-
 
233
        for s in self.get_all_suppliers():
-
 
234
            if s.name == name:
-
 
235
                supps.append(s)
-
 
236
        return supps        
-
 
237
    
-
 
238
    def get_supp_bySite(self,site):
-
 
239
        supps = []
-
 
240
        for s in self.get_all_suppliers():
-
 
241
            if s.site == site:
-
 
242
                supps.append(s)
-
 
243
        return supps
-
 
244
    
-
 
245
    
-
 
246
    
-
 
247
    def get_modId(self,brand,model):
-
 
248
        for m in self.get_all_models():
-
 
249
            if m.brand == brand:
-
 
250
                if m.model == model:
-
 
251
                    return m.id                     
-
 
252
    
-
 
253
    def get_modbyId(self,id):
-
 
254
        for m in self.get_all_models():
-
 
255
            if m.id == id:
-
 
256
                return m                     
-
 
257
        
-
 
258
    def get_modbyModel(self,model):
-
 
259
        for m in self.get_all_models():
-
 
260
            if m.model == model:
-
 
261
                return m
-
 
262
    def get_modbyBrand(self,brand):
-
 
263
        mods = []
-
 
264
        for m in self.get_all_models():
-
 
265
            if m.brand == brand:
-
 
266
                mods.append(m)
-
 
267
        return mods                     
-
 
268
    
-
 
269
    def get_prbyId(self,id):
-
 
270
        for p in self.get_all_prices():
-
 
271
            if p.id == id:
-
 
272
                return p                     
-
 
273
    
-
 
274
    def get_prbySid(self,supplier_id):
-
 
275
        prc = []
-
 
276
        for p in self.get_all_prices():
-
 
277
            if p.supplier_id == supplier_id:
-
 
278
                prc.append(p)
-
 
279
        return prc
-
 
280
                                 
-
 
281
    def get_prbyMid(self,mobile_id):
-
 
282
        prc = []
-
 
283
        for p in self.get_all_prices():
-
 
284
            if p.mobile_id == mobile_id:
-
 
285
                prc.append(p)
-
 
286
        return prc
-
 
287
    
-
 
288
    
-
 
289
    def add_supplier(self,name,site):
-
 
290
        for s in self.get_all_suppliers():
-
 
291
            if s.name == name:
-
 
292
                now = datetime.datetime.now()
-
 
293
                s.last_crawled = str(now)
-
 
294
                session.commit()
-
 
295
                return             
-
 
296
        ai = suppliers()
-
 
297
        ai.name = name
-
 
298
        ai.site = site
-
 
299
        now = datetime.datetime.now()
-
 
300
        ai.last_crawled = str(now)
-
 
301
        session.commit()
-
 
302
    
-
 
303
    def add_models(self,brand,model):
-
 
304
        for m in self.get_all_models():
-
 
305
            if m.brand == brand:
-
 
306
                if m.model == model:
-
 
307
                    return                     
-
 
308
        ai = models()
-
 
309
        ai.brand = brand
-
 
310
        ai.model = model
-
 
311
        session.commit()
-
 
312
        
-
 
313
        
-
 
314
    def add_prices(self,mobile_id,supplier_id,quoted_price,final_price,extra_info):
-
 
315
        for p in self.get_all_prices():
-
 
316
            if p.mobile_id == mobile_id:
-
 
317
                if p.supplier_id == supplier_id:
-
 
318
                    if p.extra_info == extra_info:
-
 
319
                        return                           
-
 
320
        ai = prices()
-
 
321
        ai.mobile_id = mobile_id
-
 
322
        ai.supplier_id = supplier_id
-
 
323
        ai.quoted_price = quoted_price
-
 
324
        ai.final_price = final_price
-
 
325
        ai.extra_info = extra_info
-
 
326
        session.commit()
-
 
327
        
-
 
328
    def get_price_by_model(self, model_id, supplier_id):
-
 
329
        query = prices.query.filter_by(mobile_id=model_id)
-
 
330
        query = query.filter_by(supplier_id=supplier_id)
-
 
331
        return query.one()
-
 
332
    
-
 
333
    def add_gs_info(self,mid,guaranteeinfo,shipinfo):
-
 
334
        gs = guarantee_info()
-
 
335
        gs.mid = mid
-
 
336
        gs.guaranteeinfo = guaranteeinfo 
-
 
337
        gs.shipinfo = shipinfo
-
 
338
        session.commit() 
-
 
339
    
-
 
340
    def get_all_gs_info(self):
-
 
341
        gsi = guarantee_info.query.all()
-
 
342
        return gsi
-
 
343
    
-
 
344
    def get_gs_bymid(self,mid):
-
 
345
        gsi = guarantee_info.query.filter_by(mid=mid).one()
-
 
346
        return gsi
-
 
347
        
-
 
348
if __name__ == "__main__":
-
 
349
    datastore = DataHelper()
-
 
350
    datastore.get_infibeam_csv()
-
 
351
83
352