Subversion Repositories SmartDukaan

Rev

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

Rev 13828 Rev 14257
Line 1... Line 1...
1
import urllib2
1
import urllib2
2
import simplejson as json
2
import simplejson as json
3
import pymongo
3
import pymongo
4
from dtr.utils.utils import to_java_date
4
from dtr.utils.utils import to_java_date
5
from datetime import datetime
5
from datetime import datetime
-
 
6
import optparse
-
 
7
 
-
 
8
con = None
-
 
9
parser = optparse.OptionParser()
-
 
10
parser.add_option("-m", "--m", dest="mongoHost",
-
 
11
                      default="localhost",
-
 
12
                      type="string", help="The HOST where the mongo server is running",
-
 
13
                      metavar="mongo_host")
-
 
14
 
-
 
15
(options, args) = parser.parse_args()
6
 
16
 
7
headers = { 
17
headers = { 
8
           'User-agent':'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11',
18
           'User-agent':'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11',
9
            'Accept' : 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',      
19
            'Accept' : 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',      
10
            'Accept-Language' : 'en-US,en;q=0.8',                     
20
            'Accept-Language' : 'en-US,en;q=0.8',                     
11
            'Accept-Charset' : 'ISO-8859-1,utf-8;q=0.7,*;q=0.3'
21
            'Accept-Charset' : 'ISO-8859-1,utf-8;q=0.7,*;q=0.3'
12
        }
22
        }
13
 
23
 
14
con = None
-
 
15
bestSellers = []
24
bestSellers = []
16
now = datetime.now()
25
now = datetime.now()
17
 
26
 
18
class __RankInfo:
27
class __RankInfo:
19
    
28
    
20
    def __init__(self, identifier, rank):
29
    def __init__(self, identifier, rank):
21
        self.identifier = identifier
30
        self.identifier = identifier
22
        self.rank  = rank
31
        self.rank  = rank
23
 
32
 
24
def get_mongo_connection(host='localhost', port=27017):
33
def get_mongo_connection(host=options.mongoHost, port=27017):
25
    global con
34
    global con
26
    if con is None:
35
    if con is None:
27
        print "Establishing connection %s host and port %d" %(host,port)
36
        print "Establishing connection %s host and port %d" %(host,port)
28
        try:
37
        try:
29
            con = pymongo.MongoClient(host, port)
38
            con = pymongo.MongoClient(host, port)