Subversion Repositories SmartDukaan

Rev

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

Rev 238 Rev 264
Line 8... Line 8...
8
from elixir import *
8
from elixir import *
9
import datetime
9
import datetime
10
 
10
 
11
 
11
 
12
class DataHelper:
12
class DataHelper:
-
 
13
    """
-
 
14
    Documentation for class Datahelper
-
 
15
    This class contains various methods to access the database tables
-
 
16
    crawl_id is used to retain past data for comparison, on each new crawl a new crawl_id is generated
13
    
17
    """
14
    def __init__(self):
18
    def __init__(self):
15
        #init()
19
        #init()
16
        pass
20
        pass
17
    
21
    
18
    def initxy(self):
22
    def initxy(self):
-
 
23
        """
-
 
24
        Documentation for method initxy
-
 
25
        It calls a method init() so that when one needs to access the helper methods of 
-
 
26
        this class to access database, the database tables are in the scope 
-
 
27
        """
19
        init()
28
        init()
20
        #pass
29
        #pass
21
    
30
    
-
 
31
    '''
22
    def add_vendor(self,name,url):
32
    def add_vendor(self,name,url):
23
        try:
33
        try:
24
            v = Vendor.query.filter_by(name=name)
34
            v = Vendor.query.filter_by(name=name)
25
            v = v.filter_by(url=url).one()
35
            v = v.filter_by(url=url).one()
26
            return
36
            return
27
        except:
37
        except:
28
            v = Vendor()
38
            v = Vendor()
29
            v.v_name = name
39
            v.v_name = name
30
            v.v_url = url
40
            v.v_url = url
31
            session.commit() 
41
            session.commit() 
32
            
-
 
33
    def set_all_crawled(self,bval):
-
 
34
        for ph in self.get_all_phones():
-
 
35
            ph.is_crawled = bval
-
 
36
            
-
 
37
    def set_crawled(self,url,bval):
-
 
38
        for ph in self.get_all_phones():
-
 
39
            if ph.url == url:
-
 
40
                ph.is_crawled = bval
-
 
41
        session.commit()     
-
 
42
                
-
 
43
    def get_all_phones(self):
-
 
44
        phones = PhoneItem.query.all()
-
 
45
        return phones
-
 
46
    
42
    
47
    def get_all_vendors(self):
43
    def get_all_vendors(self):
48
        vi = Vendor.query.all()
44
        vi = Vendor.query.all()
49
        return vi
45
        return vi
50
        
46
        
-
 
47
    def get_all_phones(self):
-
 
48
        phones = PhoneItem.query.all()
-
 
49
        return phones
51
        
50
        
52
    def add_new_phone(self, url, name, source):
51
    def add_new_phone(self, url, name, source):
53
        try:
52
        try:
54
            pi = PhoneItem.query.filter_by(name=name)
53
            pi = PhoneItem.query.filter_by(name=name)
55
            pi = pi.filter_by(url=url)
54
            pi = pi.filter_by(url=url)
Line 60... Line 59...
60
            pi.name = name
59
            pi.name = name
61
            pi.url = url
60
            pi.url = url
62
            pi.source = source
61
            pi.source = source
63
            session.commit()
62
            session.commit()
64
            
63
            
-
 
64
    def add_mobstoreurl(self,url):
-
 
65
        try:
-
 
66
            ai = themobilestoreurls.query.filter_by(url=url).one()
-
 
67
            return
-
 
68
        except:
-
 
69
            ai = themobilestoreurls()
-
 
70
            ai.url = url
-
 
71
            session.commit()
-
 
72
            
-
 
73
    def get_allmobstoreurls(self):
-
 
74
        ai = themobilestoreurls.query.all()
-
 
75
        return ai
-
 
76
        
-
 
77
    def add_new_mobstorephone(self,name,shown_pr,final_pr):
-
 
78
        try:
-
 
79
            ai = themobilestorephones.query.filter_by(name=name)
-
 
80
            ai = ai.filter_by(shown_price=shown_pr)
-
 
81
            ai = ai.filter_by(final_price=final_pr).one()
-
 
82
            return
-
 
83
        except:    
-
 
84
            ai = themobilestorephones()
-
 
85
            ai.name = name
-
 
86
            ai.shown_price = shown_pr
-
 
87
            ai.final_price = final_pr
-
 
88
            session.commit()
-
 
89
    
-
 
90
    def get_allmobstorephones(self):
-
 
91
        ai = themobilestorephones.query.all()
-
 
92
        return ai
-
 
93
    
-
 
94
    def add_pricesbolourl(self,url):
-
 
95
        try:
-
 
96
            ai = pricesbolourls.query.filter_by(url=url).one()
-
 
97
            return
-
 
98
        except:
-
 
99
            ai = pricesbolourls()
-
 
100
            ai.url = url
-
 
101
            session.commit()    
-
 
102
    
-
 
103
    def get_allpricesbolourl(self):
-
 
104
        vi = pricesbolourls.query.all()
-
 
105
        return vi
-
 
106
        
-
 
107
           
-
 
108
    def set_all_crawled(self,bval):
-
 
109
        for ph in self.get_all_phones():
-
 
110
            ph.is_crawled = bval
-
 
111
        session.commit()    
-
 
112
            
-
 
113
    def set_crawled(self,url,bval):
-
 
114
        for ph in self.get_all_phones():
-
 
115
            if ph.url == url:
-
 
116
                ph.is_crawled = bval
-
 
117
        session.commit()                     
-
 
118
    
65
    def add_price(self,url,price):
119
    def add_price(self,url,price):
66
        try:
120
        try:
67
            p = prices.query.filter_by(price=price)
121
            p = prices.query.filter_by(price=price)
68
            p = p.filter_by(url=url).one()
122
            p = p.filter_by(url=url).one()
69
            return
123
            return
70
        except:
124
        except:
71
            for ph in self.get_all_phones():
125
            for ph in self.get_all_phones():
72
                if ph.url == url:
126
                if ph.url == url:
73
                    ph.price = price
127
                    ph.price = price
-
 
128
            session.commit()        
-
 
129
    '''
-
 
130
   
-
 
131
    def add_newcrawler(self):
-
 
132
        """
-
 
133
        Documentation for method add_newcrawler 
-
 
134
        This method is used to add a new crawlid in crawl's table
-
 
135
        """
-
 
136
        cl = crawl()
-
 
137
        now = datetime.datetime.now()
-
 
138
        cl.crawled_date = str(now)
74
            session.commit()
139
        session.commit()
-
 
140
        
-
 
141
    def get_latestcrawler(self):
-
 
142
        """
-
 
143
        Documentation for method get_latestcrawler 
-
 
144
        This method is used to get the latest crawler from the crawl's table
-
 
145
        """
-
 
146
        cl = crawl.query.all()
-
 
147
        sz = len(cl)
-
 
148
        cl = crawl.query.filter_by(id=sz).one()
-
 
149
        return cl
-
 
150
    
-
 
151
    def get_latestcrawlerid(self):
-
 
152
        """
-
 
153
        Documentation for method get_latestcrawlerid 
-
 
154
        This method is used to get the latest crawler-id from the crawl's table
-
 
155
        """
-
 
156
        cl = crawl.query.all()
-
 
157
        sz = len(cl)
-
 
158
        cl = crawl.query.filter_by(id=sz).one().id
-
 
159
        return cl
75
        
160
        
76
    def add_infiphone(self,name,shown_price,final_price):
161
    def add_infiphone(self,name,shown_price,final_price):
-
 
162
        """
-
 
163
        Documentation for method add_infiphone 
-
 
164
        This method is used to add a phone in infibeam's table
-
 
165
        """
77
        try:
166
        try:
78
            ai = infibeam_data.query.filter_by(name=name).one()
167
            ai = infibeam_data.query.filter_by(name=name)
-
 
168
            cid = self.get_latestcrawlerid()
-
 
169
            ai = ai.filter_by(crawl_id=cid).one()
79
            return
170
            return
80
        except:
171
        except:
81
            ai = infibeam_data()
172
            ai = infibeam_data()
82
            ai.name = name
173
            ai.name = name
83
            ai.shown_price = shown_price
174
            ai.shown_price = shown_price
84
            ai.final_price = final_price
175
            ai.final_price = final_price
-
 
176
            cid = self.get_latestcrawlerid()
-
 
177
            ai.crawl_id = cid
85
            session.commit()
178
            session.commit()
86
        
179
        
-
 
180
    def get_all_infibeam_data(self):
-
 
181
        """
-
 
182
        Documentation for method get_all_infibeam_data 
-
 
183
        This method is used to retrieve all the phones in infibeam's table
-
 
184
        """
-
 
185
        cid = self.get_latestcrawlerid()
-
 
186
        phones = infibeam_data.query.filter_by(crawl_id=cid)
-
 
187
        return phones
-
 
188
        
87
    def add_univervendor(self,name,site):
189
    def add_univervendor(self,name,site):
-
 
190
        """
-
 
191
        Documentation for method add_univervendor 
-
 
192
        This method is used to add a vendor in univercell's table
-
 
193
        """
88
        try:
194
        try:
89
            ai = univercell_data.query.filter_by(name=name)
195
            ai = univercell_data.query.filter_by(name=name)
90
            ai = ai.filter_by(site=site).one()
196
            ai = ai.filter_by(site=site)
-
 
197
            cid = self.get_latestcrawlerid()
-
 
198
            ai = ai.filter_by(crawl_id=cid).one()
91
            return
199
            return
92
        except:
200
        except:
93
            ai = univercell_data()
201
            ai = univercell_data()
94
            ai.v_name = name
202
            ai.v_name = name
95
            ai.v_site = site
203
            ai.v_site = site
-
 
204
            cid = self.get_latestcrawlerid()
-
 
205
            ai.crawl_id = cid
96
            session.commit()
206
            session.commit()
97
        
207
        
98
    def get_all_univervendors(self):
208
    def get_all_univervendors(self):
-
 
209
        """
-
 
210
        Documentation for method get_all_univervendor 
-
 
211
        This method is used to retrieve all the vendors in univercell's table
-
 
212
        """
-
 
213
        cid = self.get_latestcrawlerid()
99
        vi = univercell_data.query.all()
214
        vi = univercell_data.query.filter_by(crawl_id=cid)
100
        return vi
215
        return vi
101
        
216
        
102
    def add_new_univerphone(self,name,shown_price,final_price):
217
    def add_new_univerphone(self,name,shown_price,final_price):
-
 
218
        """
-
 
219
        Documentation for method add_univerphone 
-
 
220
        This method is used to add a phone in univercell's table
-
 
221
        """
103
        try:
222
        try:
104
            ai = univercell_items.query.filter_by(name=name)
223
            ai = univercell_items.query.filter_by(name=name)
105
            ai = ai.filter_by(shown_price=shown_price)
224
            ai = ai.filter_by(shown_price=shown_price)
106
            ai = ai.filter_by(final_price=final_price).one()
225
            ai = ai.filter_by(final_price=final_price)
-
 
226
            cid = self.get_latestcrawlerid()
-
 
227
            ai = ai.filter_by(crawl_id=cid).one()
107
            return
228
            return
108
        except:
229
        except:
109
            ai = univercell_items()
230
            ai = univercell_items()
110
            ai.p_title = name
231
            ai.p_title = name
111
            ai.p_shown_price = shown_price
232
            ai.p_shown_price = shown_price
112
            ai.p_final_price = final_price
233
            ai.p_final_price = final_price
-
 
234
            cid = self.get_latestcrawlerid()
-
 
235
            ai.crawl_id = cid
113
            session.commit()
236
            session.commit()
114
            
237
            
115
    def add_ipbasic(self,name,site):
238
    def get_all_univercell_phones(self):
116
        try:
239
        """
117
            ai = indiaplaza_data.query.filter_by(name=name)
240
        Documentation for method get_all_univercell_phones 
118
            ai = ai.filter_by(site=site).one()
241
        This method is used to retrieve all the phones in univercell's table
119
            return
-
 
120
        except:
-
 
121
            ai = indiaplaza_data()
-
 
122
            ai.v_name = name
-
 
123
            ai.v_site = site
-
 
124
            session.commit()
-
 
125
        
242
        """
126
    def add_mobstoreurl(self,url):
243
        cid = self.get_latestcrawlerid()
127
        try:
-
 
128
            ai = themobilestoreurls.query.filter_by(url=url).one()
244
        phones = univercell_items.query.filter_by(crawl_id=cid)
129
            return
245
        return phones
130
        except:
-
 
131
            ai = themobilestoreurls()
-
 
132
            ai.url = url
-
 
133
            session.commit()
-
 
134
            
246
            
135
    def add_pricesbolourl(self,url):
-
 
136
        try:
-
 
137
            ai = pricesbolourls.query.filter_by(url=url).one()
-
 
138
            return
-
 
139
        except:
-
 
140
            ai = pricesbolourls()
-
 
141
            ai.url = url
-
 
142
            session.commit()    
-
 
143
    
-
 
144
    def get_allpricesbolourl(self):
-
 
145
        vi = pricesbolourls.query.all()
-
 
146
        return vi
-
 
147
       
-
 
148
    def add_naaptolurl(self,url):
247
    def add_naaptolurl(self,url):
-
 
248
        """
-
 
249
        Documentation for method add_naaptolurl 
-
 
250
        This method is used to add a url for phone in naaptol's table
-
 
251
        These are taken from sitemap.xml
-
 
252
        """
149
        try:
253
        try:
150
            n = naaptolurls.query.filter_by(url=url).one()
254
            n = naaptolurls.query.filter_by(url=url)
-
 
255
            cid = self.get_latestcrawlerid()
-
 
256
            n = n.filter_by(crawl_id=cid).one()
151
            return
257
            return
152
        except:
258
        except:
153
            ai = naaptolurls()
259
            n = naaptolurls()
154
            ai.url = url
260
            n.url = url
-
 
261
            cid = self.get_latestcrawlerid()
-
 
262
            n.crawl_id = cid
155
            session.commit()
263
            session.commit()
156
      
264
      
-
 
265
    def get_allnaaptolurls(self):
-
 
266
        """
-
 
267
        Documentation for method get_allnaaptolurls 
-
 
268
        This method is used to retrieve all the url for phones in naaptol's table
-
 
269
        """
-
 
270
        cid = self.get_latestcrawlerid()
-
 
271
        ai = naaptolurls.query.filter_by(crawl_id=cid)
-
 
272
        return ai
-
 
273
    
157
    def add_morenaaptolurl(self,url):
274
    def add_morenaaptolurl(self,url):
-
 
275
        """
-
 
276
        Documentation for method add_morenaaptolurl 
-
 
277
        This method is used to add a url for phone in naaptol's table
-
 
278
        These are the urls generated by replacing 'price' with 'features'
-
 
279
        which were redirected
-
 
280
        """
158
        try:
281
        try:
159
            n = morenaaptolurls.query.filter_by(url=url).one()
282
            n = morenaaptolurls.query.filter_by(url=url)
-
 
283
            cid = self.get_latestcrawlerid()
-
 
284
            n = n.filter_by(crawl_id=cid).one()
160
            return
285
            return
161
        except:
286
        except:
162
            try:
287
            try:
163
                n = naaptolurls.query.filter_by(url=url).one()
288
                n = morenaaptolurls.query.filter_by(url=url)
-
 
289
                cid = self.get_latestcrawlerid()
-
 
290
                n = n.filter_by(crawl_id=cid).one()
164
                return
291
                return
165
            except:
292
            except:
166
                ai = morenaaptolurls()
293
                n = morenaaptolurls()
167
                ai.url = url
294
                n.url = url
-
 
295
                cid = self.get_latestcrawlerid()
-
 
296
                n.crawl_id = cid
168
                session.commit()        
297
                session.commit()        
169
        
298
        
170
    def get_allmobstoreurls(self):
-
 
171
        ai = themobilestoreurls.query.all()
-
 
172
        return ai
-
 
173
    
-
 
174
    def get_allnaaptolurls(self):
-
 
175
        ai = naaptolurls.query.all()
-
 
176
        return ai
-
 
177
     
-
 
178
    def get_allmorenaaptolurls(self):
299
    def get_allmorenaaptolurls(self):
-
 
300
        """
-
 
301
        Documentation for method get_allmorenaaptolurls 
-
 
302
        This method is used to retrieve all the extra urls for phones in naaptol's table
-
 
303
        """
-
 
304
        cid = self.get_latestcrawlerid()
179
        ai = morenaaptolurls.query.all()
305
        ai = morenaaptolurls.query.filter_by(crawl_id=cid)
180
        return ai
306
        return ai
181
    
-
 
182
    def add_new_mobstorephone(self,name,shown_pr,final_pr):
-
 
183
        try:
307
        
184
            ai = themobilestorephones.query.filter_by(name=name)
-
 
185
            ai = ai.filter_by(shown_price=shown_pr)
-
 
186
            ai = ai.filter_by(final_price=final_pr).one()
-
 
187
            return
-
 
188
        except:    
-
 
189
            ai = themobilestorephones()
-
 
190
            ai.name = name
-
 
191
            ai.shown_price = shown_pr
-
 
192
            ai.final_price = final_pr
-
 
193
            session.commit()
-
 
194
            
-
 
195
    def add_new_mobstorephone_new(self,name,shown_pr,final_pr,extra_info):
-
 
196
        try:
-
 
197
            ai = themobilestorephones_new.query.filter_by(name=name).one()
-
 
198
            return
-
 
199
        except:    
-
 
200
            ai = themobilestorephones_new()
-
 
201
            ai.name = name
-
 
202
            ai.shown_price = shown_pr
-
 
203
            ai.final_price = final_pr
-
 
204
            ai.extra_info = extra_info
-
 
205
            session.commit()
-
 
206
            
308
            
207
    def add_new_naaptolphone(self,name,range):
309
    def add_new_naaptolphone(self,name,range):
-
 
310
        """
-
 
311
        Documentation for method add_new_naaptolphone 
-
 
312
        This method is used to add a phone in naaptol's table
-
 
313
        """
208
        temp = name.lower()
314
        temp = name.lower()
-
 
315
        cid = self.get_latestcrawlerid()
209
        if temp.find("null") != -1:
316
        if temp.find("null") != -1:
210
            return
317
            return
211
        for n in self.get_allnaaptolphones(): 
318
        for n in self.get_allnaaptolphones(): 
212
            if n.name == name:
319
            if n.name == name:
213
                if n.range == range:
320
                if n.range == range:
-
 
321
                    if n.crawl_id == cid:
214
                        return                            
322
                        return                            
215
        ai = naaptolphones()
323
        ai = naaptolphones()
216
        ai.name = name
324
        ai.name = name
217
        ai.range = range
325
        ai.range = range
-
 
326
        ai.crawl_id = self.get_latestcrawlerid()
218
        session.commit()
327
        session.commit()
219
    
328
    
-
 
329
    def get_naaptolphone(self, name, range):
-
 
330
        """
-
 
331
        Documentation for method get_naaptolphone 
-
 
332
        This method is used to retrieve a phone in naaptol's table
-
 
333
        given its name and range
-
 
334
        """
-
 
335
        query = naaptolphones.query.filter_by(name=name)
-
 
336
        query = query.filter_by(range=range)
-
 
337
        cid = self.get_latestcrawlerid()
-
 
338
        query = query.filter_by(crawl_id=cid)
-
 
339
        return query.one()
-
 
340
        
-
 
341
    def get_allnaaptolphones(self):
-
 
342
        """
-
 
343
        Documentation for method get_allnaaptolphones 
-
 
344
        This method is used to retrieve all the phone in naaptol's table
-
 
345
        """
-
 
346
        cid = self.get_latestcrawlerid()
-
 
347
        ai = naaptolphones.query.filter_by(crawl_id=cid)
-
 
348
        return ai    
-
 
349
    
220
    def add_new_ntonlinesp(self,nid,name,price):
350
    def add_new_ntonlinesp(self,nid,name,price):
-
 
351
        """
-
 
352
        Documentation for method add_new_ntonlinesp 
-
 
353
        This method is used to add a online-supplier for a particular phone
-
 
354
        in naaptol's table
-
 
355
        """
221
        try:
356
        try:
222
            n = ntonlinesp.query.filter_by(nid=nid)
357
            n = ntonlinesp.query.filter_by(nid=nid)
-
 
358
            cid = self.get_latestcrawlerid()
-
 
359
            n = n.filter_by(crawl_id=cid)
223
            n = n.filter_by(name=name).one()
360
            n = n.filter_by(name=name).one()
224
            return
361
            return
225
        except:    
362
        except:    
226
            ai = ntonlinesp()
363
            ai = ntonlinesp()
227
            ai.nid = nid
364
            ai.nid = nid
228
            ai.name = name
365
            ai.name = name
229
            ai.price = price
366
            ai.price = price
-
 
367
            cid = self.get_latestcrawlerid()
-
 
368
            ai.crawl_id = cid
230
            session.commit()
369
            session.commit()
231
        
370
        
-
 
371
    def get_allntonlinesp(self):
-
 
372
        """
-
 
373
        Documentation for method get_allntonlinesp 
-
 
374
        This method is used to retrieve all the online-suppliers in naaptol's table
-
 
375
        """
-
 
376
        cid = self.get_latestcrawlerid()
-
 
377
        ai = ntonlinesp.query.filter_by(crawl_id=cid)
-
 
378
        return ai
-
 
379
    
-
 
380
    def get_ntonlinespbynid(self,nid):
-
 
381
        """
-
 
382
        Documentation for method get_allntonlinespbynid 
-
 
383
        This method is used to retrieve all the online-supplier for a particular phone 
-
 
384
        in naaptol's table given the id of phone in naaptolphones
-
 
385
        """
-
 
386
        cid = self.get_latestcrawlerid()
-
 
387
        ai = ntonlinesp.query.filter_by(crawl_id=cid)
-
 
388
        return ai
-
 
389
    
232
    def add_new_ntofflinesp(self,nid,name,price):
390
    def add_new_ntofflinesp(self,nid,name,price):
-
 
391
        """
-
 
392
        Documentation for method add_new_ntofflinesp 
-
 
393
        This method is used to add a offline-supplier for a particular phone
-
 
394
        in naaptol's table
-
 
395
        """
233
        try:
396
        try:
234
            n = ntofflinesp.query.filter_by(nid=nid)
397
            n = ntofflinesp.query.filter_by(nid=nid)
-
 
398
            cid = self.get_latestcrawlerid()
-
 
399
            n = n.filter_by(crawl_id=cid)
235
            n = n.filter_by(name=name).one()
400
            n = n.filter_by(name=name).one()
236
            return
401
            return
237
        except:    
402
        except:    
238
            ai = ntofflinesp()
403
            ai = ntofflinesp()
239
            ai.nid = nid
404
            ai.nid = nid
240
            ai.name = name
405
            ai.name = name
241
            ai.price = price
406
            ai.price = price
-
 
407
            cid = self.get_latestcrawlerid()
-
 
408
            ai.crawl_id = cid
242
            session.commit()
409
            session.commit()
243
        
-
 
244
    def get_naaptolphone(self, name, range):
-
 
245
        query = naaptolphones.query.filter_by(name=name)
-
 
246
        query = query.filter_by(range=range)
-
 
247
        return query.one()
-
 
248
        
-
 
249
    
-
 
250
    def get_allmobstorephones(self):
-
 
251
        ai = themobilestorephones.query.all()
-
 
252
        return ai
-
 
253
    
-
 
254
    def get_allmobstorephones_new(self):
-
 
255
        ai = themobilestorephones_new.query.all()
-
 
256
        return ai
-
 
257
    
410
    
258
        
411
        
259
    def get_allnaaptolphones(self):
-
 
260
        ai = naaptolphones.query.all()
-
 
261
        return ai
-
 
262
    
-
 
263
    def get_allntonlinesp(self):
-
 
264
        ai = ntonlinesp.query.all()
-
 
265
        return ai
-
 
266
    
-
 
267
    def get_allntofflinesp(self):
412
    def get_allntofflinesp(self):
-
 
413
        """
268
        ai = ntofflinesp.query.all()
414
        Documentation for method get_allntofflinesp 
269
        return ai
415
        This method is used to retrieve all the offline-suppliers in naaptol's table
270
    
416
        """
271
    def get_ntonlinespbynid(self,nid):
417
        cid = self.get_latestcrawlerid()
272
        ai = ntonlinesp.query.filter_by(nid=nid)
418
        ai = ntofflinesp.query.filter_by(crawl_id=cid)
273
        return ai
419
        return ai
274
    
420
    
275
    def get_ntofflinespbynid(self,nid):
421
    def get_ntofflinespbynid(self,nid):
-
 
422
        """
-
 
423
        Documentation for method get_allntolinespbynid 
-
 
424
        This method is used to retrieve all the offline-supplier for a particular phone 
-
 
425
        in naaptol's table given the id of phone in naaptolphones
-
 
426
        """
276
        ai = ntofflinesp.query.filter_by(nid=nid)
427
        ai = ntofflinesp.query.filter_by(nid=nid)
-
 
428
        cid = self.get_latestcrawlerid()
-
 
429
        ai = ai.filter_by(crawl_id=cid)
-
 
430
        return ai
-
 
431
    
-
 
432
    def add_new_mobstorephone_new(self,name,shown_pr,final_pr,extra_info):
-
 
433
        """
-
 
434
        Documentation for method add_new_mobstorephone_new 
-
 
435
        This method is used to add a phone in themobilestore's table
-
 
436
        """
-
 
437
        try:
-
 
438
            ai = themobilestorephones_new.query.filter_by(name=name)
-
 
439
            cid = self.get_latestcrawlerid()
-
 
440
            ai = ai.filter_by(crawl_id=cid).one()
-
 
441
            return
-
 
442
        except:    
-
 
443
            ai = themobilestorephones_new()
-
 
444
            ai.name = name
-
 
445
            ai.shown_price = shown_pr
-
 
446
            ai.final_price = final_pr
-
 
447
            ai.extra_info = extra_info
-
 
448
            cid = self.get_latestcrawlerid()
-
 
449
            ai.crawl_id=cid
-
 
450
            session.commit()
-
 
451
    
-
 
452
    def get_allmobstorephones_new(self):
-
 
453
        """
-
 
454
        Documentation for method get_allmobstorephone_new 
-
 
455
        This method is used to retrieve all the phones in themobilestore's table
-
 
456
        """
-
 
457
        cid = self.get_latestcrawlerid()
-
 
458
        ai = themobilestorephones_new.query.filter_by(crawl_id=cid)
277
        return ai
459
        return ai
278
    
460
    
279
    def add_babuchakurl(self,url,no_pages):
461
    def add_babuchakurl(self,url,no_pages):
-
 
462
        """
-
 
463
        Documentation for method add_babuchakurl 
-
 
464
        This method is used to add a url for vendor in babuchak's table
-
 
465
        """
280
        try:
466
        try:
281
            ai = babuchak_urls.query.filter_by(url=url).one()
467
            ai = babuchak_urls.query.filter_by(url=url)
-
 
468
            cid = self.get_latestcrawlerid()
-
 
469
            ai = ai.filter_by(crawl_id=cid).one()
282
            return
470
            return
283
        except:    
471
        except:    
284
            ai = babuchak_urls()
472
            ai = babuchak_urls()
285
            ai.url = url
473
            ai.url = url
286
            ai.no_pages = no_pages 
474
            ai.no_pages = no_pages
-
 
475
            cid = self.get_latestcrawlerid()
-
 
476
            ai.crawl_id=cid 
287
            session.commit()
477
            session.commit()
288
            
478
            
289
    def get_allbabuchakurls(self):
479
    def get_allbabuchakurls(self):
-
 
480
        """
-
 
481
        Documentation for method get_allbabuchakurls 
-
 
482
        This method is used to retrieve all the vendor-urls in babuchak's table
-
 
483
        """
-
 
484
        cid = self.get_latestcrawlerid()
290
        ai = babuchak_urls.query.all()
485
        ai = babuchak_urls.query.filter_by(crawl_id=cid)
291
        return ai
486
        return ai
292
    
487
    
293
    def add_babuchakphoneurl(self,url):
488
    def add_babuchakphoneurl(self,url):
-
 
489
        """
-
 
490
        Documentation for method add_babuchakphoneurl 
-
 
491
        This method is used to add a url for phone in babuchak's table
-
 
492
        """
294
        try:
493
        try:
295
            ai = babuchak_phoneurls.query.filter_by(url=url).one()
494
            ai = babuchak_phoneurls.query.filter_by(url=url)
-
 
495
            cid = self.get_latestcrawlerid()
-
 
496
            ai = ai.filter_by(crawl_id=cid).one()
296
            return
497
            return
297
        except:    
498
        except:    
298
            ai = babuchak_phoneurls()
499
            ai = babuchak_phoneurls()
299
            ai.url = url 
500
            ai.url = url 
-
 
501
            cid = self.get_latestcrawlerid()
-
 
502
            ai.crawl_id=cid
300
            session.commit()
503
            session.commit()
301
            
504
            
302
    def get_allbabuchakphoneurls(self):
505
    def get_allbabuchakphoneurls(self):
-
 
506
        """
-
 
507
        Documentation for method get_allbabuchakphoneurls 
-
 
508
        This method is used to retrieve all the phone-urls in babuchak's table
-
 
509
        """
-
 
510
        cid = self.get_latestcrawlerid()
303
        ai = babuchak_phoneurls.query.all()
511
        ai = babuchak_phoneurls.query.filter_by(crawl_id=cid)
304
        return ai
512
        return ai
305
        
513
        
306
    def add_babuchakphone(self,name,shown_price,final_price):
514
    def add_babuchakphone(self,name,shown_price,final_price):
-
 
515
        """
-
 
516
        Documentation for method add_babuchakphone 
-
 
517
        This method is used to add a phone in babuchak's table
-
 
518
        """
307
        try:
519
        try:
308
            ai = babuchak_phones.query.filter_by(name=name).one()
520
            ai = babuchak_phones.query.filter_by(name=name)
-
 
521
            cid = self.get_latestcrawlerid()
-
 
522
            ai = ai.filter_by(crawl_id=cid).one()
309
            return
523
            return
310
        except:
524
        except:
311
            ai = babuchak_phones()
525
            ai = babuchak_phones()
312
            ai.name = name
526
            ai.name = name
313
            ai.shown_price = shown_price
527
            ai.shown_price = shown_price
314
            ai.final_price = final_price    
528
            ai.final_price = final_price    
-
 
529
            cid = self.get_latestcrawlerid()
-
 
530
            ai.crawl_id=cid
315
            session.commit()
531
            session.commit()
316
            
532
            
317
    def get_allbabuchakphones(self):
533
    def get_allbabuchakphones(self):
-
 
534
        """
-
 
535
        Documentation for method get_allbabuchakphones 
-
 
536
        This method is used to retrieve all the phone in babuchak's table
-
 
537
        """
-
 
538
        cid = self.get_latestcrawlerid()
318
        ai = babuchak_phones.query.all()
539
        ai = babuchak_phones.query.filter_by(crawl_id=cid)
319
        return ai       
540
        return ai       
-
 
541
    
-
 
542
    def add_ipbasic(self,name,site):
-
 
543
        """
-
 
544
        Documentation for method add_ipbasic 
-
 
545
        This method is used to add a url for phone in indiaplaza's table
-
 
546
        """
-
 
547
        try:
-
 
548
            ai = indiaplaza_data.query.filter_by(name=name)
-
 
549
            ai = ai.filter_by(site=site).one()
-
 
550
            cid = self.get_latestcrawlerid()
-
 
551
            ai = ai.filter_by(crawl_id=cid).one()
-
 
552
            return
-
 
553
        except:
-
 
554
            ai = indiaplaza_data()
-
 
555
            ai.v_name = name
-
 
556
            ai.v_site = site
-
 
557
            cid = self.get_latestcrawlerid()
-
 
558
            ai.crawl_id=cid
-
 
559
            session.commit()
320
                      
560
                              
321
    def get_all_ipbasic(self):
561
    def get_all_ipbasic(self):
-
 
562
        """
-
 
563
        Documentation for method get_all_ipbasic 
-
 
564
        This method is used to retrieve all phone-urls in indiaplaza's table
-
 
565
        """
-
 
566
        cid = self.get_latestcrawlerid()
322
        vi = indiaplaza_data.query.all()
567
        vi = indiaplaza_data.query.filter_by(crawl_id=cid)
323
        return vi
568
        return vi
324
        
569
        
325
    def add_ipextra(self,name,shown_price,final_price,guarantee,shipinfo):
570
    def add_ipextra(self,name,shown_price,final_price,guarantee,shipinfo):
-
 
571
        """
-
 
572
        Documentation for method add_ipextra 
-
 
573
        This method is used to add a phone in indiaplaza's table
-
 
574
        """
326
        try:
575
        try:
327
            ai = indiaplaza_items.query.filter_by(p_name=name)
576
            ai = indiaplaza_items.query.filter_by(p_name=name)
328
            ai = ai.filter_by(p_shown_price=shown_price)
577
            ai = ai.filter_by(p_shown_price=shown_price)
329
            ai = ai.filter_by(p_final_price=final_price)
578
            ai = ai.filter_by(p_final_price=final_price)
330
            ai = ai.filter_by(p_guaranteeinfo=guarantee)
579
            ai = ai.filter_by(p_guaranteeinfo=guarantee)
-
 
580
            cid = self.get_latestcrawlerid()
-
 
581
            ai = ai.filter_by(crawl_id=cid)
331
            ai = ai.filter_by(p_shipinfo=shipinfo).one()
582
            ai = ai.filter_by(p_shipinfo=shipinfo).one()
332
            return
583
            return
333
        except:
584
        except:
334
            ai = indiaplaza_items()
585
            ai = indiaplaza_items()
335
            ai.p_name = name
586
            ai.p_name = name
336
            ai.p_shown_price = shown_price
587
            ai.p_shown_price = shown_price
337
            ai.p_final_price = final_price
588
            ai.p_final_price = final_price
338
            ai.p_guaranteeinfo = guarantee
589
            ai.p_guaranteeinfo = guarantee
339
            ai.p_shipinfo = shipinfo
590
            ai.p_shipinfo = shipinfo
-
 
591
            cid = self.get_latestcrawlerid()
-
 
592
            ai.crawl_id=cid
340
            session.commit()
593
            session.commit()
341
            
-
 
342
    def get_all_infibeam_data(self):
-
 
343
        phones = infibeam_data.query.all()
-
 
344
        return phones
-
 
345
    
-
 
346
    
594
    
347
    def get_all_indiaplaza_phones(self):
595
    def get_all_indiaplaza_phones(self):
-
 
596
        """
348
        phones = indiaplaza_items.query.all()
597
        Documentation for method get_all_indiaplaza_phones 
349
        return phones
598
        This method is used to retrieve all the phones in indiaplaza's table
350
                    
599
        """
351
    def get_all_univercell_phones(self):
600
        cid = self.get_latestcrawlerid()
352
        phones = univercell_items.query.all()
601
        phones = indiaplaza_items.query.filter_by(crawl_id=cid)
353
        return phones
602
        return phones
-
 
603
                
-
 
604
    def set_extra_vars(self,var,val,desc):    
-
 
605
        """
-
 
606
        Documentation for method set_extra_vars  
-
 
607
        This method is used to add a variable for a particular supplier.
-
 
608
        Some suppliers has no fixed count of number of pages on which they have data
-
 
609
        so to deal with that this function is used to set variables. 
-
 
610
        """
-
 
611
        try:
-
 
612
            tm = extra_vars.query.filter_by(var=var).one()
-
 
613
            tm.val = val
-
 
614
            tm.desc = desc
-
 
615
        except:
-
 
616
            tm = extra_vars()
-
 
617
            tm.var = var
-
 
618
            tm.val = val
-
 
619
            tm.desc = desc       
-
 
620
        
-
 
621
    def get_extra_vars(self,var):
-
 
622
        """
-
 
623
        Documentation for method get_extra_vars  
-
 
624
        This method is used to retrieve a variable's value given its name 
-
 
625
        """
-
 
626
        try:
-
 
627
            #print "in try"
-
 
628
            tm = extra_vars.query.filter_by(var=var).one()
-
 
629
        except:
-
 
630
            #print "in except"
-
 
631
            tm = "EMPTY"
-
 
632
        return tm.val
354
    
633
    
355
    def get_infibeam_csv(self):
634
    def add_supplier(self,name,site):
-
 
635
        """
-
 
636
        Documentation for method add_suppliers 
-
 
637
        This method is used to add a supplier in supplier's table
-
 
638
        """
356
        phones = self.get_all_infibeam_phones()
639
        for s in self.get_all_suppliers():
-
 
640
            if s.name == name:
-
 
641
                now = datetime.datetime.now()
-
 
642
                s.last_crawled = str(now)
-
 
643
                session.commit()
-
 
644
                return             
357
        print phones
645
        ai = suppliers()
-
 
646
        ai.name = name
-
 
647
        ai.site = site
-
 
648
        now = datetime.datetime.now()
-
 
649
        ai.last_crawled = str(now)
-
 
650
        session.commit()
358
    
651
        
359
    def get_all_suppliers(self):
652
    def get_all_suppliers(self):
-
 
653
        """
-
 
654
        Documentation for method get_all_suppliers 
-
 
655
        This method is used to retrieve all the suppliers from the supplier's table
-
 
656
        """
360
        sup = suppliers.query.all()
657
        sup = suppliers.query.all()
361
        return sup
658
        return sup
362
    
659
    
363
    def get_all_models(self):
-
 
364
        mod = models.query.all()
-
 
365
        return mod
-
 
366
    
-
 
367
    def get_all_prices(self):
-
 
368
        pr = prices.query.all()
-
 
369
        return pr
-
 
370
    
-
 
371
    def get_suppId(self,name):
660
    def get_suppId(self,name):
-
 
661
        """
-
 
662
        Documentation for method get_suppId 
-
 
663
        This method is used to retrieve id of the supplier given his name
-
 
664
        from the supplier's table
-
 
665
        """
372
        for s in self.get_all_suppliers():
666
        for s in self.get_all_suppliers():
373
            if s.name == name:
667
            if s.name == name:
374
                return s.id
668
                return s.id
375
    
669
    
376
    def get_supp_byId(self,id):
670
    def get_supp_byId(self,id):
-
 
671
        """
-
 
672
        Documentation for method get_supp_byId 
-
 
673
        This method is used to retrieve a supplier given his id
-
 
674
        from the supplier's table
-
 
675
        """
377
        for s in self.get_all_suppliers():
676
        for s in self.get_all_suppliers():
378
            if s.id == id:
677
            if s.id == id:
379
                return s
678
                return s
380
    
679
    
381
    def get_supp_byName(self,name):
680
    def get_supp_byName(self,name):
-
 
681
        """
-
 
682
        Documentation for method get_suppbyName 
-
 
683
        This method is used to retrieve a supplier given his name
-
 
684
        from the supplier's table
-
 
685
        """
382
        supps = []
686
        supps = []
383
        for s in self.get_all_suppliers():
687
        for s in self.get_all_suppliers():
384
            if s.name == name:
688
            if s.name == name:
385
                supps.append(s)
689
                supps.append(s)
386
        return supps        
690
        return supps        
387
    
691
    
388
    def get_supp_bySite(self,site):
692
    def get_supp_bySite(self,site):
-
 
693
        """
-
 
694
        Documentation for method get_suppbySite 
-
 
695
        This method is used to retrieve a supplier given his url
-
 
696
        from the supplier's table
-
 
697
        """
389
        supps = []
698
        supps = []
390
        for s in self.get_all_suppliers():
699
        for s in self.get_all_suppliers():
391
            if s.site == site:
700
            if s.site == site:
392
                supps.append(s)
701
                supps.append(s)
393
        return supps
702
        return supps
394
    
703
    
-
 
704
    def add_models(self,brand,model):
-
 
705
        """
-
 
706
        Documentation for method add_models 
-
 
707
        This method is used to add a model in model's table
-
 
708
        """
-
 
709
        cid = self.get_latestcrawlerid()
-
 
710
        for m in self.get_all_models():
-
 
711
            if m.brand == brand:
-
 
712
                if m.model == model:
-
 
713
                    if m.crawl_id == cid:
-
 
714
                        return                     
-
 
715
        ai = models()
-
 
716
        ai.brand = brand
-
 
717
        ai.model = model
-
 
718
        ai.crawl_id = cid
-
 
719
        session.commit()
395
    
720
        
-
 
721
    def get_all_models(self):
-
 
722
        """
-
 
723
        Documentation for method get_all_models 
-
 
724
        This method is used to retrieve all the model from the model's table
-
 
725
        """
-
 
726
        cid = self.get_latestcrawlerid()
-
 
727
        mod = models.query.filter_by(crawl_id=cid)
-
 
728
        return mod
396
    
729
    
397
    def get_modId(self,brand,model):
730
    def get_modId(self,brand,model):
-
 
731
        """
-
 
732
        Documentation for method get_modId 
-
 
733
        This method is used to retrieve the id of a model
-
 
734
        given its name from the model's table
-
 
735
        """
-
 
736
        cid = self.get_latestcrawlerid()
398
        for m in self.get_all_models():
737
        for m in self.get_all_models():
399
            if m.brand == brand:
738
            if m.brand == brand:
400
                if m.model == model:
739
                if m.model == model:
-
 
740
                    if m.crawl_id == cid:
401
                    return m.id                     
741
                        return m.id                     
402
    
742
    
403
    def get_modbyId(self,id):
743
    def get_modbyId(self,id):
-
 
744
        """
-
 
745
        Documentation for method get_modId 
-
 
746
        This method is used to retrieve a model given its id from the model's table
-
 
747
        """
-
 
748
        cid = self.get_latestcrawlerid()
404
        for m in self.get_all_models():
749
        for m in self.get_all_models():
405
            if m.id == id:
750
            if m.id == id and m.crawl_id == cid:
406
                return m                     
751
                return m                     
407
        
752
        
408
    def get_modbyModel(self,model):
753
    def get_modbyModel(self,model):
-
 
754
        """
-
 
755
        Documentation for method get_modId 
-
 
756
        This method is used to retrieve a model given its name from the model's table
-
 
757
        """
-
 
758
        cid = self.get_latestcrawlerid()
409
        for m in self.get_all_models():
759
        for m in self.get_all_models():
410
            if m.model == model:
760
            if m.model == model and m.crawl_id == cid:
411
                return m
761
                return m
412
            
762
            
413
    def get_modbyBrand(self,brand):
763
    def get_modbyBrand(self,brand):
-
 
764
        """
-
 
765
        Documentation for method get_modId 
-
 
766
        This method is used to retrieve a model given its brand-name from the model's table
-
 
767
        """
-
 
768
        cid = self.get_latestcrawlerid()
414
        mods = []
769
        mods = []
415
        for m in self.get_all_models():
770
        for m in self.get_all_models():
416
            if m.brand == brand:
771
            if m.brand == brand and m.crawl_id == cid:
417
                mods.append(m)
772
                mods.append(m)
418
        return mods                     
773
        return mods                     
419
    
774
    
-
 
775
    def add_prices(self,mobile_id,supplier_id,quoted_price,final_price,extra_info):
-
 
776
        """
-
 
777
        Documentation for method add_prices 
-
 
778
        This method is used to add all the info for a phone in prices's table
-
 
779
        """
-
 
780
        cid = self.get_latestcrawlerid()
-
 
781
        for p in self.get_all_prices():
-
 
782
            if p.mobile_id == mobile_id:
-
 
783
                if p.supplier_id == supplier_id:
-
 
784
                    if p.extra_info == extra_info and p.crawl_id == cid:
-
 
785
                        return                           
-
 
786
        ai = prices()
-
 
787
        ai.mobile_id = mobile_id
-
 
788
        ai.supplier_id = supplier_id
-
 
789
        ai.quoted_price = quoted_price
-
 
790
        ai.final_price = final_price
-
 
791
        ai.extra_info = extra_info
-
 
792
        ai.crawl_id = cid
-
 
793
        session.commit()
-
 
794
        
-
 
795
    def get_all_prices(self):
-
 
796
        """
-
 
797
        Documentation for method get_all_prices 
-
 
798
        This method is used to retrieve all the info for all the phones in prices's table
-
 
799
        """
-
 
800
        cid = self.get_latestcrawlerid()
-
 
801
        pr = prices.query.filter_by(crawl_id=cid)
-
 
802
        return pr
-
 
803
    
420
    def get_prbyId(self,id):
804
    def get_prbyId(self,id):
-
 
805
        """
-
 
806
        Documentation for method get_prbyId 
-
 
807
        This method is used to retrieve all the info for a phone given its id in prices's table
-
 
808
        """
-
 
809
        cid = self.get_latestcrawlerid()
421
        for p in self.get_all_prices():
810
        for p in self.get_all_prices():
422
            if p.id == id:
811
            if p.id == id and p.crawl_id == cid:
423
                return p                     
812
                return p                     
424
    
813
    
425
    def get_prbySid(self,supplier_id):
814
    def get_prbySid(self,supplier_id):
-
 
815
        """
-
 
816
        Documentation for method get_prbySid 
-
 
817
        This method is used to retrieve all the info for a phone in prices's table 
-
 
818
        given its supplier-id 
-
 
819
        """
-
 
820
        cid = self.get_latestcrawlerid()
426
        prc = []
821
        prc = []
427
        for p in self.get_all_prices():
822
        for p in self.get_all_prices():
428
            if p.supplier_id == supplier_id:
823
            if p.supplier_id == supplier_id and p.crawl_id == cid:
429
                prc.append(p)
824
                prc.append(p)
430
        return prc
825
        return prc
431
                                 
826
                                 
432
    def get_prbyMid(self,mobile_id):
827
    def get_prbyMid(self,mobile_id):
-
 
828
        """
-
 
829
        Documentation for method get_prbySid 
-
 
830
        This method is used to retrieve all the info for a phone in prices's table 
-
 
831
        given its model-id 
-
 
832
        """
-
 
833
        cid = self.get_latestcrawlerid()
433
        prc = []
834
        prc = []
434
        for p in self.get_all_prices():
835
        for p in self.get_all_prices():
435
            if p.mobile_id == mobile_id:
836
            if p.mobile_id == mobile_id and p.crawl_id == cid:
436
                prc.append(p)
837
                prc.append(p)
437
        return prc
838
        return prc
438
    
-
 
439
    
-
 
440
    def add_supplier(self,name,site):
-
 
441
        for s in self.get_all_suppliers():
-
 
442
            if s.name == name:
-
 
443
                now = datetime.datetime.now()
-
 
444
                s.last_crawled = str(now)
-
 
445
                session.commit()
-
 
446
                return             
-
 
447
        ai = suppliers()
-
 
448
        ai.name = name
-
 
449
        ai.site = site
-
 
450
        now = datetime.datetime.now()
-
 
451
        ai.last_crawled = str(now)
-
 
452
        session.commit()
-
 
453
    
-
 
454
    def add_models(self,brand,model):
-
 
455
        for m in self.get_all_models():
-
 
456
            if m.brand == brand:
-
 
457
                if m.model == model:
-
 
458
                    return                     
-
 
459
        ai = models()
-
 
460
        ai.brand = brand
-
 
461
        ai.model = model
-
 
462
        session.commit()
-
 
463
        
-
 
464
        
-
 
465
    def add_prices(self,mobile_id,supplier_id,quoted_price,final_price,extra_info):
-
 
466
        for p in self.get_all_prices():
-
 
467
            if p.mobile_id == mobile_id:
-
 
468
                if p.supplier_id == supplier_id:
-
 
469
                    if p.extra_info == extra_info:
-
 
470
                        return                           
-
 
471
        ai = prices()
-
 
472
        ai.mobile_id = mobile_id
-
 
473
        ai.supplier_id = supplier_id
-
 
474
        ai.quoted_price = quoted_price
-
 
475
        ai.final_price = final_price
-
 
476
        ai.extra_info = extra_info
-
 
477
        session.commit()
-
 
478
        
839
              
479
    def get_price_by_model(self, model_id, supplier_id):
840
    def get_price_by_model(self, model_id, supplier_id):
-
 
841
        """
-
 
842
        Documentation for method get_prbySid 
-
 
843
        This method is used to retrieve all the info for a phone in prices's table 
-
 
844
        given its model-name 
-
 
845
        """
-
 
846
        cid = self.get_latestcrawlerid()
480
        query = prices.query.filter_by(mobile_id=model_id)
847
        query = prices.query.filter_by(mobile_id=model_id)
481
        query = query.filter_by(supplier_id=supplier_id)
848
        query = query.filter_by(supplier_id=supplier_id)
-
 
849
        query = query.filter_by(crawl_id=cid)
482
        return query.one()
850
        return query.one()
483
    
851
    
484
    def add_gs_info(self,mid,guaranteeinfo,shipinfo):
852
    def add_gs_info(self,mid,guaranteeinfo,shipinfo):
-
 
853
        """
-
 
854
        Documentation for method add_gs_info 
-
 
855
        This method is used to add guarantee and ship info for a phone 
-
 
856
        """
-
 
857
        cid = self.get_latestcrawlerid()
485
        try:
858
        try:
486
            gs = guarantee_info.query.filter_by(mid=mid)
859
            gs = guarantee_info.query.filter_by(mid=mid)
487
            gs = gs.filter_by(guaranteeinfo=guaranteeinfo)
860
            gs = gs.filter_by(guaranteeinfo=guaranteeinfo)
-
 
861
            gs = gs.filter_by(crawl_id=cid)
488
            gs = gs.filter_by(shipinfo=shipinfo).one()
862
            gs = gs.filter_by(shipinfo=shipinfo).one()
489
            return
863
            return
490
        except:
864
        except:
491
            gs = guarantee_info()
865
            gs = guarantee_info()
492
            gs.mid = mid
866
            gs.mid = mid
493
            gs.guaranteeinfo = guaranteeinfo 
867
            gs.guaranteeinfo = guaranteeinfo 
494
            gs.shipinfo = shipinfo
868
            gs.shipinfo = shipinfo
-
 
869
            gs.crawl_id = cid
495
            session.commit() 
870
            session.commit() 
496
        
871
        
497
    def get_all_gs_info(self):
872
    def get_all_gs_info(self):
-
 
873
        """
-
 
874
        Documentation for method get_all_gs_info 
-
 
875
        This method is used to retrieve guarantee and ship info for all the phones 
-
 
876
        """
-
 
877
        cid = self.get_latestcrawlerid()
498
        gsi = guarantee_info.query.all()
878
        gsi = guarantee_info.query.filter_by(crawl_id=cid)
499
        return gsi
879
        return gsi
500
    
880
    
501
    def get_gs_bymid(self,mid):
881
    def get_gs_bymid(self,mid):
502
        gsi = guarantee_info.query.filter_by(mid=mid).one()
-
 
503
        return gsi
-
 
504
        
-
 
505
    def set_extra_vars(self,var,val,desc):    
-
 
506
        try:
-
 
507
            tm = extra_vars.query.filter_by(var=var).one()
-
 
508
            tm.val = val
-
 
509
            tm.desc = desc
-
 
510
        except:
-
 
511
            tm = extra_vars()
-
 
512
            tm.var = var
-
 
513
            tm.val = val
-
 
514
            tm.desc = desc       
-
 
515
        
-
 
516
    def get_extra_vars(self,var):
-
 
517
        try:
-
 
518
            #print "in try"
-
 
519
            tm = extra_vars.query.filter_by(var=var).one()
-
 
520
        except:
-
 
521
            #print "in except"
-
 
522
            tm = "EMPTY"
-
 
523
        return tm.val
-
 
524
    
-
 
525
if __name__ == "__main__":
-
 
526
    datastore = DataHelper()
-
 
527
    datastore.get_infibeam_csv()
-
 
528
882
        """
-
 
883
        Documentation for method get_gs_bymid 
-
 
884
        This method is used to retrieve guarantee and ship info for a phones
-
 
885
        given its phone-id 
-
 
886
        """
-
 
887
        cid = self.get_latestcrawlerid()
-
 
888
        gsi = guarantee_info.query.filter_by(crawl_id=cid).one()
-
 
889
        return gsi  
-
 
890
    
-
 
891
529
892