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
from BeautifulSoup import BeautifulSoup
2
from BeautifulSoup import BeautifulSoup
3
import pymongo
3
import pymongo
4
import re
4
import re
-
 
5
from dtr.utils.utils import to_java_date
-
 
6
from datetime import datetime
5
 
7
 
6
asin_regex = r'/([A-Z0-9]{10})'
-
 
7
con = None
8
con = None
8
bestSellers = []
9
bestSellers = []
-
 
10
now = datetime.now()
9
 
11
 
10
class __RankInfo:
12
class __RankInfo:
11
    
13
    
12
    def __init__(self, identifier, rank):
14
    def __init__(self, identifier, rank):
13
        self.identifier = identifier
15
        self.identifier = identifier
Line 93... Line 95...
93
        print x.identifier,
95
        print x.identifier,
94
        col = get_mongo_connection().Catalog.MasterData.find({'identifier':x.identifier.strip()})
96
        col = get_mongo_connection().Catalog.MasterData.find({'identifier':x.identifier.strip()})
95
        print "count sku",
97
        print "count sku",
96
        print '\t',
98
        print '\t',
97
        print len(list(col))
99
        print len(list(col))
98
        get_mongo_connection().Catalog.MasterData.update({'identifier':x.identifier.strip()}, {'$set' : {'rank':x.rank}}, multi=True)
100
        get_mongo_connection().Catalog.MasterData.update({'identifier':x.identifier.strip()}, {'$set' : {'rank':x.rank,'updatedOn':to_java_date(now)}}, multi=True)
99
 
101
 
100
def resetRanks(category):
102
def resetRanks(category):
-
 
103
    oldRankedItems = get_mongo_connection().Catalog.MasterData.find({'rank':{'$gt':0},'source_id':2,'category':category})
-
 
104
    for item in oldRankedItems:
101
    get_mongo_connection().Catalog.MasterData.update({'category':category,'source_id':2}, {'$set' : {'rank':0}}, multi=True)
105
        get_mongo_connection().Catalog.MasterData.update({'_id':item['_id']}, {'$set' : {'rank':0,'updatedOn':to_java_date(now)}}, multi=True)
102
        
106
        
103
def main():
107
def main():
104
    scrapeBestSellerMobiles()
108
    scrapeBestSellerMobiles()
105
    if len(bestSellers) > 0:
109
    if len(bestSellers) > 0:
106
        resetRanks('Mobiles')
110
        resetRanks('Mobiles')