Subversion Repositories SmartDukaan

Rev

Rev 20592 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
20571 kshitij.so 1
import pymongo
2
import os
3
import json
4
from xml.etree.ElementTree import parse, Element
5
from xml import etree
6
 
7
con=None
8
 
9
filePath="/var/lib/tomcat6/webapps/export/javascripts/autosuggesthotspot.json"
10
solrPath = "/var/lib/tomcat6/webapps/export/solr/"
11
 
12
def get_mongo_connection(host='localhost', port=27017):
13
    global con
14
    if con is None:
15
        print "Establishing connection %s host and port %d" %(host,port)
16
        try:
17
            con = pymongo.MongoClient(host, port)
18
        except Exception, e:
19
            print e
20
            return None
21
    return con
22
 
23
def generate_auto_suggest():
24
    PATH = os.path.expanduser(filePath)
25
    if os.path.isfile(PATH):
26
        try:
27
            os.remove(os.path.expanduser(filePath))
28
        except OSError:
29
            pass
30
    output = open(filePath, 'ab+')
31
    all = get_mongo_connection().Hotspot.HotspotEntity.find()
20592 kshitij.so 32
    autoSuggestMap = {}
20571 kshitij.so 33
    for a in all:
20592 kshitij.so 34
        autoSuggestMap[a['title']] = [a['title']]
35
    json.dump(autoSuggestMap, output)
20571 kshitij.so 36
 
37
def alter_solr_xml():
38
    all = get_mongo_connection().Hotspot.HotspotEntity.find()
39
    for a in all:
40
        fileName = str(a['_id'])+"_irdata_solr.xml"
41
        doc = parse(solrPath+fileName)
42
        root = doc.find('doc')
20856 amit.gupta 43
        co = Element("field", name="P_120537")
44
        co.text="Yes"
20571 kshitij.so 45
        root.append(co)
46
        doc.write(solrPath+fileName)
47
 
48
def main():
49
    generate_auto_suggest()
50
    alter_solr_xml()
51
 
52
if __name__ == '__main__':
53
    main()