Skip to content

Commit

Permalink
Bump to 3.0.0, node modules post-installed
Browse files Browse the repository at this point in the history
  • Loading branch information
nsamarin committed Jul 14, 2022
1 parent 6c74b0e commit 525e44d
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 7 deletions.
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1 +1 @@
recursive-include scraper/node_modules *
include scraper/package.json
2 changes: 1 addition & 1 deletion scraper/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .scraper import *

# Version of the google-play-scraper-py package.
__version__ = "0.2.4"
__version__ = "0.3.0"
2 changes: 1 addition & 1 deletion scraper/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"dependencies": {
"google-play-scraper": "^8.1.0"
"google-play-scraper": "*"
}
}
27 changes: 24 additions & 3 deletions scraper/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 525e44d

Please sign in to comment.