Last active
March 3, 2022 03:10
-
-
Save prot0man/702bef7a1926af19a047509b88497c8f to your computer and use it in GitHub Desktop.
Get Play Store Application Version
This file contains hidden or 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
import requests | |
import urllib | |
import re | |
import argparse | |
import logging | |
logging.basicConfig(level=logging.INFO) | |
logger = logging.getLogger("getversion") | |
PLAY_URL_FMT_STR = "https://play.google.com/store/apps/details?id=%s&hl=%s&gl=%s" | |
VERSION_RE = re.compile("Current Version.*?>([a-zA-Z0-9\.\- ]+)<", re.M) | |
def parse_app_version(content): | |
result = VERSION_RE.search(content) | |
if result: | |
return result.groups(1) | |
def get_app_version(app_name): | |
hl = "en_US" | |
gl = "US" | |
url = PLAY_URL_FMT_STR % (app_name, hl, gl) | |
response = requests.get(url) | |
data = response.content.decode("utf8") | |
result = parse_app_version(data) | |
if result is None or len(result[0]) < 2: | |
index = data.find("Current Version") | |
if index != -1: | |
# if we did find a fragment of the regular expression, emit a log message that shows | |
# where the RE may have failed. | |
logger.warning("Failed to get version data:\'%s'" % (data[index:index + 256])) | |
return result | |
def parse_args(): | |
ap = argparse.ArgumentParser() | |
ap.add_argument("app_name") | |
args = ap.parse_args() | |
return args | |
def main(): | |
args = parse_args() | |
version = get_app_version(args.app_name) | |
logger.info("Got version: %s" % version) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tested against this list of appids. Note that google uses "Varies by version" as a version for some of these, so our RE matches horrendous things like that.