Skip to content
This repository was archived by the owner on Nov 18, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ pip install playstats
'Varies with device'
>>> app.content_rating()
'Rated for 3+'
>>> app.keyword_rank('whats app instant messenger')
2
```


Expand Down
25 changes: 25 additions & 0 deletions playstats/appstat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -111,3 +112,27 @@ def title(self):
selector = CSSSelector('.id-app-title')
match = self.tree.xpath(selector.path)
return match[0].text

def keyword_rank(self, search):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move this to a new file playstat.py just like appstat.py because this is not related to a particular app but is a general stat.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, as a seperate research tool i guess! Optimisation websites offer this simple function for over 50$/month !

# 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.
# 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()
result_tree = html.fromstring(result)
match = result_tree.xpath('//@data-docid')
i = 1
rank = 1
try:
while(i < 500):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not keep it as i<=100 and increment i by 1?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docid set has the same docid reoccurring 5 times.. that's why incrementing the count by 5. Multiplying was somehow offsetting the result. Will look into this though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay.

if match[i] == self.package_name:
return rank
else:
i = i + 5
rank = rank + 1
except:
return 0
return 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's return None instead of 0.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It shall be done!