Subversion Repositories SmartDukaan

Rev

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

Rev 13754 Rev 13828
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 shop2020.model.v1.catalog.script.DataWeaveConsumer import __ProductInfo
4
from dtr.utils.utils import to_java_date
-
 
5
from datetime import datetime
5
 
6
 
6
headers = { 
7
headers = { 
7
           'User-agent':'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11',
8
           'User-agent':'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11',
8
            'Accept' : 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',      
9
            'Accept' : 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',      
9
            'Accept-Language' : 'en-US,en;q=0.8',                     
10
            'Accept-Language' : 'en-US,en;q=0.8',                     
10
            'Accept-Charset' : 'ISO-8859-1,utf-8;q=0.7,*;q=0.3'
11
            'Accept-Charset' : 'ISO-8859-1,utf-8;q=0.7,*;q=0.3'
11
        }
12
        }
12
 
13
 
13
con = None
14
con = None
14
bestSellers = []
15
bestSellers = []
-
 
16
now = datetime.now()
15
 
17
 
16
class __RankInfo:
18
class __RankInfo:
17
    
19
    
18
    def __init__(self, identifier, rank):
20
    def __init__(self, identifier, rank):
19
        self.identifier = identifier
21
        self.identifier = identifier
Line 64... Line 66...
64
                r_info = __RankInfo((identifiers['supcs'])[0],rank)
66
                r_info = __RankInfo((identifiers['supcs'])[0],rank)
65
                bestSellers.append(r_info)
67
                bestSellers.append(r_info)
66
            rank += 1
68
            rank += 1
67
 
69
 
68
def resetRanks(category):
70
def resetRanks(category):
-
 
71
    oldRankedItems = get_mongo_connection().Catalog.MasterData.find({'rank':{'$gt':0},'source_id':3,'category':category})
-
 
72
    for item in oldRankedItems:
69
    get_mongo_connection().Catalog.MasterData.update({'category':category,'source_id':3}, {'$set' : {'rank':0}}, multi=True)
73
        get_mongo_connection().Catalog.MasterData.update({'_id':item['_id']}, {'$set' : {'rank':0,'updatedOn':to_java_date(now)}}, multi=True)
70
 
74
 
71
def commitBestSellers():
75
def commitBestSellers():
72
    print "Rank",
76
    print "Rank",
73
    print '\t',
77
    print '\t',
74
    print 'Identifier'
78
    print 'Identifier'
Line 78... Line 82...
78
        print x.identifier,
82
        print x.identifier,
79
        col = get_mongo_connection().Catalog.MasterData.find({'identifier':x.identifier.strip()})
83
        col = get_mongo_connection().Catalog.MasterData.find({'identifier':x.identifier.strip()})
80
        print "count sku",
84
        print "count sku",
81
        print '\t',
85
        print '\t',
82
        print len(list(col))
86
        print len(list(col))
83
        get_mongo_connection().Catalog.MasterData.update({'identifier':x.identifier.strip()}, {'$set' : {'rank':x.rank}}, multi=True)
87
        get_mongo_connection().Catalog.MasterData.update({'identifier':x.identifier.strip()}, {'$set' : {'rank':x.rank,'updatedOn':to_java_date(now)}}, multi=True)
84
 
88
 
85
def main():
89
def main():
86
    scrapeBestSellerMobiles()
90
    scrapeBestSellerMobiles()
87
    if len(bestSellers) > 0:
91
    if len(bestSellers) > 0:
88
        resetRanks('Mobiles')
92
        resetRanks('Mobiles')