This repository has been archived by the owner on Nov 7, 2022. It is now read-only.
Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
PlaystoreDownloader/scripts/crawl_top_apps_by_category.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
41 lines (32 sloc)
1.23 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import os | |
from urllib.parse import urlparse, parse_qs | |
from playstore.playstore import Playstore | |
def main(): | |
# Use the private credentials for this script. | |
api = Playstore( | |
os.path.join( | |
os.path.dirname(os.path.realpath(__file__)), | |
os.path.pardir, | |
"private_credentials.json", | |
) | |
) | |
# Get the categories in the Google Play Store. | |
res = api.protobuf_to_dict(api.get_store_categories())["category"] | |
store_categories = set( | |
map(lambda x: parse_qs(urlparse(x["dataUrl"]).query).get("cat", [None])[0], res) | |
) | |
# Get the top top_num free apps in each category. | |
top_num = 10 | |
for cat in store_categories: | |
if not cat: | |
continue | |
doc = api.list_app_by_category(cat, "apps_topselling_free", top_num).doc[0] | |
for app in doc.child if doc.docid else doc.child[0].child: | |
rating = app.aggregateRating.starRating | |
# Print package name, category and rating. | |
print(f"{app.docid}|{cat}|{rating}") | |
if __name__ == "__main__": | |
# Run the script from the main directory of the project by using this command: | |
# pipenv run python -m scripts.crawl_top_apps_by_category | |
main() |