From 525e44d37c2fdd82ec7d6dd71cccfd2990cb7a82 Mon Sep 17 00:00:00 2001 From: nsamarin Date: Thu, 14 Jul 2022 07:50:23 -0700 Subject: [PATCH] Bump to 3.0.0, node modules post-installed --- MANIFEST.in | 2 +- scraper/__init__.py | 2 +- scraper/package.json | 2 +- scraper/wrapper.py | 27 ++++++++++++++++++++++++--- setup.py | 2 +- 5 files changed, 28 insertions(+), 7 deletions(-) diff --git a/MANIFEST.in b/MANIFEST.in index 546e7ae..c0c2711 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1 +1 @@ -recursive-include scraper/node_modules * +include scraper/package.json diff --git a/scraper/__init__.py b/scraper/__init__.py index 53fdd22..1575c58 100644 --- a/scraper/__init__.py +++ b/scraper/__init__.py @@ -1,4 +1,4 @@ from .scraper import * # Version of the google-play-scraper-py package. -__version__ = "0.2.4" +__version__ = "0.3.0" diff --git a/scraper/package.json b/scraper/package.json index 450c660..6158c6b 100644 --- a/scraper/package.json +++ b/scraper/package.json @@ -1,5 +1,5 @@ { "dependencies": { - "google-play-scraper": "^8.1.0" + "google-play-scraper": "*" } } diff --git a/scraper/wrapper.py b/scraper/wrapper.py index ec447e9..d59c3af 100644 --- a/scraper/wrapper.py +++ b/scraper/wrapper.py @@ -15,20 +15,37 @@ class _Wrapper: node_dir = [x if x != '' else os.path.sep for x in NODE_DIR.split(os.path.sep)] require_dir = "'{}'".format("', '".join(node_dir)) + init_script = "var gplay = require(path.join({}));" api_script = ( "var gplay = require(path.join({})){};" "gplay.{}({{{}}})" ".then(JSON.stringify).then(console.log).catch(console.log);" ) - var_script = ( "var gplay = require(path.join({})){};" "let x = gplay.{};" "console.log(JSON.stringify(x));" ) - def __init__(self, memoization=False, vars=[]): + def __init__(self, memoization=False): self.memoization = '.memoized()' if memoization else '' + + def check_modules(self): + args = ['node', '-e', self.init_script.format(self.require_dir)] + try: + subprocess.run(args, capture_output=True, check=True) + except subprocess.CalledProcessError as e: + stderr = e.stderr.decode() + if 'Error: Cannot find module' in stderr: + return False + raise ScraperException(stderr) from None + return True + + def update_modules(self): + install_args = ['npm', '--prefix', SELF_DIR, 'update'] + return subprocess.run(install_args, capture_output=True, check=True) + + def set_vars(self, vars=[]): for var in vars: setattr(_Wrapper, var, self._execute_var(var)) @@ -73,7 +90,11 @@ def stringify(x): # Private module attributes. -_wrapper = _Wrapper(vars=['collection', 'category', 'age', 'sort']) +_wrapper = _Wrapper() +_wrapper.update_modules() + +# Set wrapper fields. +_wrapper.set_vars(vars=['collection', 'category', 'age', 'sort']) # Public module attributes. collection = _wrapper.collection diff --git a/setup.py b/setup.py index 9419b9e..cf34428 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ setup( name='google-play-scraper-py', - version='0.2.4', + version='0.3.0', description='Scrape application data from the Google Play store.', long_description=long_description, long_description_content_type='text/markdown',