Subversion Repositories SmartDukaan

Rev

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

Rev 13985 Rev 14186
Line 1... Line 1...
1
import pysolr
1
import pysolr
2
import json
-
 
3
import pymongo
2
import pymongo
-
 
3
import shutil
-
 
4
import json
-
 
5
import os
4
 
6
 
5
con=None
7
con=None
6
 
8
 
-
 
9
filePath = '/tmp/autosuggest.json'
-
 
10
destFilePath = '/home/kshitij/'
-
 
11
 
7
categoryMap = {3:'Mobiles',5:'Tablets'}
12
categoryMap = {3:'Mobiles',5:'Tablets'}
8
SOURCE_MAP = {'AMAZON':1,'FLIPKART':2,'SNAPDEAL':3,'SAHOLIC':4}
13
SOURCE_MAP = {'AMAZON':1,'FLIPKART':2,'SNAPDEAL':3,'SAHOLIC':4}
9
xstr = lambda s: s or ""
14
xstr = lambda s: s or ""
10
 
15
 
11
class __SkuInfo:
16
class __SkuInfo:
Line 31... Line 36...
31
        
36
        
32
solr = pysolr.Solr("http://104.200.25.40:8080/solr/", timeout=10)
37
solr = pysolr.Solr("http://104.200.25.40:8080/solr/", timeout=10)
33
 
38
 
34
def pushData():
39
def pushData():
35
    l = []
40
    l = []
-
 
41
    catalogMap = {}
36
    items = get_mongo_connection().Catalog.MasterData.find({'source_id' : { "$in": SOURCE_MAP.values() } })
42
    items = get_mongo_connection().Catalog.MasterData.find({'source_id' : { "$in": SOURCE_MAP.values() } })
37
    print items.count()
43
    print items.count()
38
    for item in items:
44
    for item in items:
39
        title = xstr(item['brand'])+" "+xstr(item['model_name'])
45
        title = xstr(item['brand'])+" "+xstr(item['model_name'])
-
 
46
        if not catalogMap.has_key(str(item['skuBundleId'])+" "+title):
-
 
47
            catalogMap[str(item['skuBundleId'])+" "+title] = [title ,item['thumbnail']]
40
        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'], \
48
        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'], \
41
                        int(item['source_id']),(item['source']),title,(item['thumbnail']), long(item['priceUpdatedOn']))
49
                        int(item['source_id']),(item['source']),title,(item['thumbnail']), long(item['priceUpdatedOn']))
42
        l.append(s_info.__dict__)
50
        l.append(s_info.__dict__)
43
    solr.add(l)
51
    solr.add(l)
-
 
52
    
-
 
53
    
-
 
54
    PATH = os.path.expanduser(filePath)
-
 
55
    if os.path.isfile(PATH):
-
 
56
        try:
-
 
57
            os.remove(os.path.expanduser(filePath))
-
 
58
        except OSError:
-
 
59
            pass
-
 
60
    output = open(filePath, 'ab+')
-
 
61
    json.dump(catalogMap, output)
-
 
62
    output.close()
-
 
63
    shutil.copy2(filePath, destFilePath)
-
 
64
    
-
 
65
    
44
 
66
 
45
def get_mongo_connection(host='localhost', port=27017):
67
def get_mongo_connection(host='localhost', port=27017):
46
    global con
68
    global con
47
    if con is None:
69
    if con is None:
48
        print "Establishing connection %s host and port %d" %(host,port)
70
        print "Establishing connection %s host and port %d" %(host,port)
Line 52... Line 74...
52
            print e
74
            print e
53
            return None
75
            return None
54
    return con
76
    return con
55
 
77
 
56
def main():
78
def main():
57
    print "TADA"
-
 
58
    pushData()
79
    pushData()
-
 
80
    
59
if __name__=='__main__':
81
if __name__=='__main__':
60
    main()
82
    main()
61
83