From b19739e6baff79ac21b0e0752da977ddc0c06a8d Mon Sep 17 00:00:00 2001 From: teg khanna Date: Sun, 25 Feb 2018 00:51:04 +0530 Subject: [PATCH 1/4] added keyword rank --- playstats/appstat.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/playstats/appstat.py b/playstats/appstat.py index df7cd4e..1fdb697 100644 --- a/playstats/appstat.py +++ b/playstats/appstat.py @@ -8,6 +8,7 @@ def __init__(self, package_name): self.app_url = "https://play.google.com/store/apps/details?id=%s&hl=en" % package_name self.content = urlopen(self.app_url).read() self.tree = html.fromstring(self.content) + self.package_name = package_name def rating(self): # Returns rating out of 5 @@ -111,3 +112,23 @@ def title(self): selector = CSSSelector('.id-app-title') match = self.tree.xpath(selector.path) return match[0].text + + def keyword_rank(self, search): + # Returns the rank of the app on searching the passed keyword. + # Useful for playstore search optimisation. + # The rank is based on the search in the playstore website. + # Rank maybe off by 1 or 2 due to playstore advertisement. + search_string = search.replace(' ', '%20') + url = 'https://play.google.com/store/search?q=' + search_string + '&c=apps&hl=en' + result = urlopen(url).read() + result_tree = html.fromstring(result) + match = result_tree.xpath('//@data-docid') + i = 1 + rank = 1 + while(i < 400): + if match[i] == self.package_name: + return rank + else: + i = i + 5 + rank = rank + 1 + return 0 From 19c31bd8632e3006013f9f850f9639095544f0fd Mon Sep 17 00:00:00 2001 From: teg khanna Date: Sun, 25 Feb 2018 00:52:36 +0530 Subject: [PATCH 2/4] added keyword rank --- playstats/appstat.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/playstats/appstat.py b/playstats/appstat.py index 1fdb697..a37e428 100644 --- a/playstats/appstat.py +++ b/playstats/appstat.py @@ -118,6 +118,7 @@ def keyword_rank(self, search): # Useful for playstore search optimisation. # The rank is based on the search in the playstore website. # Rank maybe off by 1 or 2 due to playstore advertisement. + # 0 means search didn't contain the app for the first 100 results search_string = search.replace(' ', '%20') url = 'https://play.google.com/store/search?q=' + search_string + '&c=apps&hl=en' result = urlopen(url).read() @@ -125,7 +126,7 @@ def keyword_rank(self, search): match = result_tree.xpath('//@data-docid') i = 1 rank = 1 - while(i < 400): + while(i < 500): if match[i] == self.package_name: return rank else: From 7b31c722dbc39e58158b42336b9196ca09a01ec4 Mon Sep 17 00:00:00 2001 From: Teg khanna Date: Sun, 25 Feb 2018 01:03:18 +0530 Subject: [PATCH 3/4] added use --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 33801a1..0600b64 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,8 @@ pip install playstats 'Varies with device' >>> app.content_rating() 'Rated for 3+' +>>> app.keyword_rank('whats app instant messenger') +2 ``` From 769c197b661864f0b6da303a006aeee362699d1f Mon Sep 17 00:00:00 2001 From: teg khanna Date: Sun, 25 Feb 2018 12:45:07 +0530 Subject: [PATCH 4/4] fixed exception caused by limited search --- playstats/appstat.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/playstats/appstat.py b/playstats/appstat.py index a37e428..24a0eda 100644 --- a/playstats/appstat.py +++ b/playstats/appstat.py @@ -126,10 +126,13 @@ def keyword_rank(self, search): match = result_tree.xpath('//@data-docid') i = 1 rank = 1 - while(i < 500): - if match[i] == self.package_name: - return rank - else: - i = i + 5 - rank = rank + 1 + try: + while(i < 500): + if match[i] == self.package_name: + return rank + else: + i = i + 5 + rank = rank + 1 + except: + return 0 return 0