Subversion Repositories SmartDukaan

Rev

Rev 13974 | Rev 14204 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

import pysolr
import json
import pymongo

con=None

categoryMap = {3:'Mobiles',5:'Tablets'}
SOURCE_MAP = {'AMAZON':1,'FLIPKART':2,'SNAPDEAL':3,'SAHOLIC':4}
xstr = lambda s: s or ""

class __SkuInfo:
    
    def __init__(self, id, skuBundleId, brand, model_name, source_product_name, category_id, category, available_price, mrp, in_stock, \
                 source_id, store, title, thumbnail, priceUpdatedOn):
        self.id = id
        self.skuBundleId = skuBundleId
        self.brand = brand
        self.model_name = model_name
        self.source_product_name = source_product_name
        self.category_id = category_id
        self.category = category
        self.available_price = available_price
        self.mrp = mrp
        self.in_stock = in_stock
        self.source_id = source_id
        self.store = store
        self.title= title
        self.thumbnail = thumbnail
        self.priceUpdatedOn = priceUpdatedOn
        
        
solr = pysolr.Solr("http://104.200.25.40:8080/solr/", timeout=10)

def pushData():
    l = []
    items = get_mongo_connection().Catalog.MasterData.find({'source_id' : { "$in": SOURCE_MAP.values() } })
    print items.count()
    for item in items:
        title = xstr(item['brand'])+" "+xstr(item['model_name'])
        s_info = __SkuInfo(str(item['_id']),int(item['skuBundleId']),(item['brand']),(item['model_name']),(item['source_product_name']),int(item['category_id']),categoryMap.get(item['category_id']),float(item['available_price']),float(item['mrp']),item['in_stock'], \
                        int(item['source_id']),(item['source']),title,(item['thumbnail']), long(item['priceUpdatedOn']))
        l.append(s_info.__dict__)
    solr.add(l)

def get_mongo_connection(host='localhost', port=27017):
    global con
    if con is None:
        print "Establishing connection %s host and port %d" %(host,port)
        try:
            con = pymongo.MongoClient(host, port)
        except Exception, e:
            print e
            return None
    return con

def main():
    print "TADA"
    pushData()
if __name__=='__main__':
    main()