Subversion Repositories SmartDukaan

Rev

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

Rev 14379 Rev 15088
Line 26... Line 26...
26
            'Accept-Charset' : 'ISO-8859-1,utf-8;q=0.7,*;q=0.3'
26
            'Accept-Charset' : 'ISO-8859-1,utf-8;q=0.7,*;q=0.3'
27
        }
27
        }
28
 
28
 
29
bestSellers = []
29
bestSellers = []
30
now = datetime.now()
30
now = datetime.now()
-
 
31
BASE_URL = "snapdeal.com/"
31
 
32
 
32
class __RankInfo:
33
class __RankInfo:
33
    
34
    
34
    def __init__(self, identifier, rank, category):
35
    def __init__(self, identifier, rank, category, product_name, page_url):
35
        self.identifier = identifier
36
        self.identifier = identifier
36
        self.rank  = rank
37
        self.rank  = rank
37
        self.category  =category
38
        self.category  =category
-
 
39
        self.product_name = product_name
-
 
40
        self.page_url = page_url 
38
 
41
 
39
def get_mongo_connection(host=options.mongoHost, port=27017):
42
def get_mongo_connection(host=options.mongoHost, port=27017):
40
    global con
43
    global con
41
    if con is None:
44
    if con is None:
42
        print "Establishing connection %s host and port %d" %(host,port)
45
        print "Establishing connection %s host and port %d" %(host,port)
Line 57... Line 60...
57
        response = urllib2.urlopen(request)
60
        response = urllib2.urlopen(request)
58
 
61
 
59
        json_input = response.read()
62
        json_input = response.read()
60
        info = json.loads(json_input)
63
        info = json.loads(json_input)
61
        for offer in info['productOfferGroupDtos']:
64
        for offer in info['productOfferGroupDtos']:
-
 
65
            #print offer['name']
-
 
66
            #print offer['pageUrl']
62
            for identifiers in offer['offers']:
67
            for identifiers in offer['offers']:
63
                r_info = __RankInfo((identifiers['supcs'])[0],rank, None)
68
                r_info = __RankInfo((identifiers['supcs'])[0],rank, None, offer['name'], offer['pageUrl'])
64
                bestSellers.append(r_info)
69
                bestSellers.append(r_info)
65
            rank += 1
70
            rank += 1
66
 
71
 
67
def scrapeBestSellerTablets():
72
def scrapeBestSellerTablets():
68
    global bestSellers
73
    global bestSellers
Line 76... Line 81...
76
 
81
 
77
        json_input = response.read()
82
        json_input = response.read()
78
        info = json.loads(json_input)
83
        info = json.loads(json_input)
79
        for offer in info['productOfferGroupDtos']:
84
        for offer in info['productOfferGroupDtos']:
80
            for identifiers in offer['offers']:
85
            for identifiers in offer['offers']:
81
                r_info = __RankInfo((identifiers['supcs'])[0],rank, None)
86
                r_info = __RankInfo((identifiers['supcs'])[0],rank, None,offer['name'], offer['pageUrl'])
82
                bestSellers.append(r_info)
87
                bestSellers.append(r_info)
83
            rank += 1
88
            rank += 1
84
 
89
 
85
def resetRanks(category):
90
def resetRanks(category):
86
    oldRankedItems = get_mongo_connection().Catalog.MasterData.find({'rank':{'$gt':0},'source_id':3,'category':category})
91
    oldRankedItems = get_mongo_connection().Catalog.MasterData.find({'rank':{'$gt':0},'source_id':3,'category':category})
Line 112... Line 117...
112
            <table border="1" style="width:100%;">
117
            <table border="1" style="width:100%;">
113
            <thead>
118
            <thead>
114
            <tr><th>Identifier</th>
119
            <tr><th>Identifier</th>
115
            <th>Category</th>
120
            <th>Category</th>
116
            <th>Rank</th>
121
            <th>Rank</th>
-
 
122
            <th>Product Name</th>
-
 
123
            <th>Page Url</th>
117
            </tr></thead>
124
            </tr></thead>
118
            <tbody>"""
125
            <tbody>"""
119
    for item in exceptionList:
126
    for item in exceptionList:
120
        message+="""<tr>
127
        message+="""<tr>
121
        <td style="text-align:center">"""+(item.identifier)+"""</td>
128
        <td style="text-align:center">"""+(item.identifier)+"""</td>
122
        <td style="text-align:center">"""+(item.category)+"""</td>
129
        <td style="text-align:center">"""+(item.category)+"""</td>
123
        <td style="text-align:center">"""+str(item.rank)+"""</td>
130
        <td style="text-align:center">"""+str(item.rank)+"""</td>
-
 
131
        <td style="text-align:center">"""+str(item.product_name)+"""</td>
-
 
132
        <td style="text-align:center">"""+str(BASE_URL+item.page_url)+"""</td>
124
        </tr>"""
133
        </tr>"""
125
    message+="""</tbody></table></body></html>"""
134
    message+="""</tbody></table></body></html>"""
126
    print message
135
    print message
127
    #recipients = ['kshitij.sood@saholic.com']
136
    #recipients = ['kshitij.sood@saholic.com']
128
    recipients = ['rajneesh.arora@saholic.com','kshitij.sood@saholic.com','chaitnaya.vats@saholic.com','manoj.kumar@saholic.com']
137
    recipients = ['rajneesh.arora@saholic.com','kshitij.sood@saholic.com','chaitnaya.vats@saholic.com','manoj.kumar@saholic.com']