Skip to content

Commit 72eb307

Browse files
committed
Add rating count. Also, this command is powered by magic
1 parent 253c805 commit 72eb307

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

plugins/amazon.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import requests
2+
import re
23
from bs4 import BeautifulSoup
34
from urllib.parse import urlparse
45

@@ -40,13 +41,16 @@ def amazon(text):
4041
price = item.find('span', {'class': 'a-color-price'}).text
4142

4243
try:
44+
pattern = re.compile(r'product-reviews')
4345
rating = item.find('i', {'class': 'a-icon-star'}).find('span', {'class': 'a-icon-alt'}).text
46+
num_ratings = item.find('a', {'href': pattern}).text
47+
rating_str = "{} ({} ratings)".format(rating, num_ratings)
4448
except AttributeError:
45-
rating = "No Ratings"
49+
rating_str = "No Ratings"
4650

4751
# clean up garbage url
4852
o = urlparse(item.find('a', {'class': 's-access-detail-page'})['href'])
4953
url = o.scheme + "://" + o.netloc + o.path + "?linkCode=as2&tag=cloudbot-20"
5054
url = web.try_shorten(url)
5155

52-
return "\x02{}\x02 ({}) - {} - {}".format(title, price, rating, url)
56+
return "\x02{}\x02 ({}) - {} - {}".format(title, price, rating_str, url)

0 commit comments

Comments
 (0)