Rev 13974 | Rev 14204 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
import pysolrimport jsonimport pymongocon=NonecategoryMap = {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 = idself.skuBundleId = skuBundleIdself.brand = brandself.model_name = model_nameself.source_product_name = source_product_nameself.category_id = category_idself.category = categoryself.available_price = available_priceself.mrp = mrpself.in_stock = in_stockself.source_id = source_idself.store = storeself.title= titleself.thumbnail = thumbnailself.priceUpdatedOn = priceUpdatedOnsolr = 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 conif con is None:print "Establishing connection %s host and port %d" %(host,port)try:con = pymongo.MongoClient(host, port)except Exception, e:print ereturn Nonereturn condef main():print "TADA"pushData()if __name__=='__main__':main()