Subversion Repositories SmartDukaan

Rev

Rev 13931 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
13828 kshitij.so 1
import pysolr
2
import json
3
import pymongo
4
 
5
con=None
6
 
7
categoryMap = {3:'Mobiles',5:'Tablets'}
8
SOURCE_MAP = {'AMAZON':1,'FLIPKART':2,'SNAPDEAL':3,'SAHOLIC':4}
9
xstr = lambda s: s or ""
10
 
11
class __SkuInfo:
12
 
13
    def __init__(self, id, skuBundleId, brand, model_name, category_id, category, available_price, mrp, in_stock, \
14
                 source_id, store, title, thumbnail, updatedOn):
15
        self.id = id
16
        self.skuBundleId = skuBundleId
17
        self.brand = brand
18
        self.model_name = model_name
19
        self.category_id = category_id
20
        self.category = category
21
        self.available_price = available_price
22
        self.mrp = mrp
23
        self.in_stock = in_stock
24
        self.source_id = source_id
25
        self.store = store
26
        self.title= title
27
        self.thumbnail = thumbnail
28
        self.updatedOn = updatedOn
29
 
30
 
31
solr = pysolr.Solr("http://104.200.25.40:8080/solr/", timeout=10)
32
 
33
def pushData():
34
    l = []
35
    items = get_mongo_connection().Catalog.MasterData.find({'source_id' : { "$in": SOURCE_MAP.values() } })
36
    print items.count()
37
    for item in items:
38
        title = xstr(item['brand'])+" "+xstr(item['model_name'])
39
        s_info = __SkuInfo(str(item['_id']),int(item['skuBundleId']),str(item['brand']),str(item['model_name']),int(item['category_id']),categoryMap.get(item['category_id']),float(item['available_price']),float(item['mrp']),item['in_stock'], \
40
                        int(item['source_id']),str(item['source']),title,str(item['thumbnail']), long(item['updatedOn']))
41
        l.append(s_info.__dict__)
42
    solr.add(l)
43
 
44
def get_mongo_connection(host='localhost', port=27017):
45
    global con
46
    if con is None:
47
        print "Establishing connection %s host and port %d" %(host,port)
48
        try:
49
            con = pymongo.MongoClient(host, port)
50
        except Exception, e:
51
            print e
52
            return None
53
    return con
54
 
55
def main():
56
    print "TADA"
57
    pushData()
58
if __name__=='__main__':
59
    main()