Subversion Repositories SmartDukaan

Rev

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

Rev 16381 Rev 16464
Line 20... Line 20...
20
 
20
 
21
(options, args) = parser.parse_args()
21
(options, args) = parser.parse_args()
22
 
22
 
23
 
23
 
24
exceptionList = []
24
exceptionList = []
25
asin_regex = r'/([A-Z0-9]{10})'
-
 
26
bestSellers = []
25
bestSellers = []
27
now = datetime.now()
26
now = datetime.now()
28
 
27
 
29
 
28
 
30
class __RankInfo:
29
class __RankInfo:
Line 70... Line 69...
70
    for x in bestSellers:
69
    for x in bestSellers:
71
        print x.rank,
70
        print x.rank,
72
        print '\t',
71
        print '\t',
73
        print x.identifier,
72
        print x.identifier,
74
        col = get_mongo_connection().Catalog.MasterData.find({'identifier':x.identifier, 'source_id':6})
73
        col = get_mongo_connection().Catalog.MasterData.find({'identifier':x.identifier, 'source_id':6})
75
        print "count sku",
74
        print "count sku",len(list(col))
76
        print '\n',
75
        print '\n',
77
        if len(list(col)) == 0:
76
        if len(list(col)) == 0:
78
            x.category = category
77
            x.category = category
79
            exceptionList.append(x)
78
            exceptionList.append(x)
80
        else:
79
        else:
81
            get_mongo_connection().Catalog.MasterData.update({'identifier':x.identifier, 'source_id':6 }, {'$set' : {'rank':x.rank,'updatedOn':to_java_date(now)}})
80
            get_mongo_connection().Catalog.MasterData.update({'identifier':x.identifier, 'source_id':6 }, {'$set' : {'rank':x.rank,'updatedOn':to_java_date(now)}})
82
        
81
        
83
def scrapeBestSellerTablets():
82
def scrapeBestSellerTablets():
84
    global bestSellers
83
    global bestSellers
-
 
84
    bestSellers = []
85
    rank = 0
85
    rank = 0
86
    bestSellerTabletsUrl = 'https://catalog.paytm.com/v1/g/electronics/mobile-accessories/headsets?page_count=%d&items_per_page=25&sort_popular=1'
86
    bestSellerTabletsUrl = 'https://catalog.paytm.com/v1/g/electronics/mobile-accessories/headsets?page_count=%d&items_per_page=25&sort_popular=1'
87
    for i in range(1,5):
87
    for i in range(1,5):
88
        data = fetchResponseUsingProxy(bestSellerTabletsUrl%(i))
88
        data = fetchResponseUsingProxy(bestSellerTabletsUrl%(i))
89
        jsonResponse = json.loads(data)
89
        jsonResponse = json.loads(data)
Line 117... Line 117...
117
    message+="""</tbody></table></body></html>"""
117
    message+="""</tbody></table></body></html>"""
118
    print message
118
    print message
119
    #recipients = ['amit.gupta@saholic.com']
119
    #recipients = ['amit.gupta@saholic.com']
120
    recipients = ['rajneesh.arora@saholic.com','kshitij.sood@saholic.com','chaitnaya.vats@saholic.com','manoj.kumar@saholic.com','amit.gupta@saholic.com']
120
    recipients = ['rajneesh.arora@saholic.com','kshitij.sood@saholic.com','chaitnaya.vats@saholic.com','manoj.kumar@saholic.com','amit.gupta@saholic.com']
121
    msg = MIMEMultipart()
121
    msg = MIMEMultipart()
122
    msg['Subject'] = "Amazon Best Sellers" + ' - ' + str(datetime.now())
122
    msg['Subject'] = "Paytm Best Sellers" + ' - ' + str(datetime.now())
123
    msg['From'] = ""
123
    msg['From'] = ""
124
    msg['To'] = ",".join(recipients)
124
    msg['To'] = ",".join(recipients)
125
    msg.preamble = "Amazon Best Sellers" + ' - ' + str(datetime.now())
125
    msg.preamble = "Paytm Best Sellers" + ' - ' + str(datetime.now())
126
    html_msg = MIMEText(message, 'html')
126
    html_msg = MIMEText(message, 'html')
127
    msg.attach(html_msg)
127
    msg.attach(html_msg)
128
    
128
    
129
    smtpServer = smtplib.SMTP('localhost')
129
    smtpServer = smtplib.SMTP('localhost')
130
    smtpServer.set_debuglevel(1)
130
    smtpServer.set_debuglevel(1)
Line 138... Line 138...
138
            
138
            
139
            
139
            
140
def main():
140
def main():
141
    scrapeBestSellerMobiles()
141
    scrapeBestSellerMobiles()
142
    if len(bestSellers) > 0:
142
    if len(bestSellers) > 0:
143
        resetRanks(6)
143
        resetRanks(3)
144
        commitBestSellers("MOBILE")
144
        commitBestSellers("MOBILE")
145
    scrapeBestSellerTablets()
145
    scrapeBestSellerTablets()
146
    if len(bestSellers) > 0:
146
    if len(bestSellers) > 0:
147
        resetRanks(5)
147
        resetRanks(5)
148
        commitBestSellers("TABLET")
148
        commitBestSellers("TABLET")