| Line 68... |
Line 68... |
| 68 |
url = (data['value']['smartUrl']).replace("http://dl.flipkart.com/dl", "http://www.flipkart.com")
|
68 |
url = (data['value']['smartUrl']).replace("http://dl.flipkart.com/dl", "http://www.flipkart.com")
|
| 69 |
r_info = __RankInfo(identifier, rank, 5, title, url)
|
69 |
r_info = __RankInfo(identifier, rank, 5, title, url)
|
| 70 |
bestSellers.append(r_info)
|
70 |
bestSellers.append(r_info)
|
| 71 |
rank = rank + 1
|
71 |
rank = rank + 1
|
| 72 |
|
72 |
|
| 73 |
def commitBestSellers(category):
|
73 |
def commitBestSellers():
|
| 74 |
global exceptionList
|
74 |
global exceptionList
|
| 75 |
for x in bestSellers:
|
75 |
for x in bestSellers:
|
| 76 |
col = get_mongo_connection(host=options.mongoHost).Catalog.MasterData.find({'identifier':x.identifier.strip(),'category_id':category})
|
76 |
col = get_mongo_connection(host=options.mongoHost).Catalog.MasterData.find({'identifier':x.identifier.strip()})
|
| 77 |
if len(list(col)) == 0:
|
77 |
if len(list(col)) == 0:
|
| 78 |
x.category = category
|
- |
|
| 79 |
exceptionList.append(x)
|
78 |
exceptionList.append(x)
|
| 80 |
else:
|
79 |
else:
|
| 81 |
get_mongo_connection(host=options.mongoHost).Catalog.MasterData.update({'identifier':x.identifier.strip(),'category_id':category}, {'$set' : {'rank':x.rank,'updatedOn':to_java_date(now)}}, multi=True)
|
80 |
get_mongo_connection(host=options.mongoHost).Catalog.MasterData.update({'identifier':x.identifier.strip()}, {'$set' : {'rank':x.rank,'updatedOn':to_java_date(now)}}, multi=True)
|
| 82 |
|
81 |
|
| 83 |
def resetRanks(category):
|
82 |
def resetRanks(category):
|
| 84 |
get_mongo_connection(host=options.mongoHost).Catalog.MasterData.update({'category_id':category}, {'$set' : {'rank':0,'updatedOn':to_java_date(now)}}, multi=True)
|
83 |
get_mongo_connection(host=options.mongoHost).Catalog.MasterData.update({'category_id':category}, {'$set' : {'rank':0,'updatedOn':to_java_date(now)}}, multi=True)
|
| 85 |
|
84 |
|
| 86 |
def sendEmail():
|
85 |
def sendEmail():
|
| Line 103... |
Line 102... |
| 103 |
<td style="text-align:center">"""+(CATEGORY_MAP.get(item.category))+"""</td>
|
102 |
<td style="text-align:center">"""+(CATEGORY_MAP.get(item.category))+"""</td>
|
| 104 |
<td style="text-align:center">"""+str(item.rank)+"""</td>
|
103 |
<td style="text-align:center">"""+str(item.rank)+"""</td>
|
| 105 |
<td style="text-align:center">"""+(item.url)+"""</td>
|
104 |
<td style="text-align:center">"""+(item.url)+"""</td>
|
| 106 |
</tr>"""
|
105 |
</tr>"""
|
| 107 |
message+="""</tbody></table></body></html>"""
|
106 |
message+="""</tbody></table></body></html>"""
|
| - |
|
107 |
print message
|
| 108 |
#recipients = ['kshitij.sood@saholic.com']
|
108 |
#recipients = ['kshitij.sood@saholic.com']
|
| 109 |
recipients = ['rajneesh.arora@saholic.com','kshitij.sood@saholic.com','chaitnaya.vats@saholic.com','manoj.kumar@saholic.com']
|
109 |
recipients = ['rajneesh.arora@saholic.com','kshitij.sood@saholic.com','chaitnaya.vats@saholic.com','manoj.kumar@saholic.com']
|
| 110 |
msg = MIMEMultipart()
|
110 |
msg = MIMEMultipart()
|
| 111 |
msg['Subject'] = "Flipkart Best Sellers" + ' - ' + str(datetime.now())
|
111 |
msg['Subject'] = "Flipkart Best Sellers" + ' - ' + str(datetime.now())
|
| 112 |
msg['From'] = ""
|
112 |
msg['From'] = ""
|
| Line 124... |
Line 124... |
| 124 |
except:
|
124 |
except:
|
| 125 |
print "Error: unable to send email."
|
125 |
print "Error: unable to send email."
|
| 126 |
|
126 |
|
| 127 |
def main():
|
127 |
def main():
|
| 128 |
scrapeBestSellerMobiles()
|
128 |
scrapeBestSellerMobiles()
|
| 129 |
if len(bestSellers) > 0:
|
- |
|
| 130 |
resetRanks(3)
|
129 |
resetRanks(3)
|
| 131 |
commitBestSellers(3)
|
- |
|
| 132 |
scrapeBestSellerTablets()
|
130 |
scrapeBestSellerTablets()
|
| 133 |
if len(bestSellers) > 0:
|
- |
|
| 134 |
resetRanks(5)
|
131 |
resetRanks(5)
|
| 135 |
commitBestSellers(5)
|
132 |
commitBestSellers()
|
| 136 |
sendEmail()
|
133 |
sendEmail()
|
| 137 |
|
134 |
|
| 138 |
if __name__=='__main__':
|
135 |
if __name__=='__main__':
|
| 139 |
main()
|
136 |
main()
|
| 140 |
|
137 |
|