Skip to content
This repository was archived by the owner on Nov 18, 2019. It is now read-only.

Commit e0b4cb8

Browse files
Fetch total reviews for an app.
1 parent 044f102 commit e0b4cb8

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

playstats/appstat.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,25 @@ def __init__(self, package_name):
99
self.content = urlopen(self.app_url).read()
1010
self.tree = html.fromstring(self.content)
1111

12-
def get_rating(self):
12+
def rating(self):
1313
selector = CSSSelector('.score')
1414
match = self.tree.xpath(selector.path)
1515
rating = float(match[0].text)
1616
return rating
1717

18-
def get_all_ratings(self):
18+
def all_ratings(self):
1919
# Returns number of ratings corresponding to different stars
2020
# in the form of dictionary.
2121
selector = CSSSelector('.bar-number')
2222
matches = self.tree.xpath(selector.path)
2323
ratings = [int(x.text.replace(',', '')) for x in matches]
24-
ratings_dict = {star: no_of_ratings for (star, no_of_ratings) in zip(range(5, 0, -1), ratings)}
24+
ratings_dict = {star: no_of_ratings for (star, no_of_ratings) in
25+
zip(range(5, 0, -1), ratings)}
2526
return ratings_dict
27+
28+
def total_reviews(self):
29+
# Returns total number of reviews for an app.
30+
selector = CSSSelector('.reviews-num')
31+
match = self.tree.xpath(selector.path)
32+
total_reviews = int(match[0].text.replace(',', ''))
33+
return total_reviews

0 commit comments

Comments
 (0)