diff --git a/scraper/__init__.py b/scraper/__init__.py index 25c1906..53fdd22 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.3" +__version__ = "0.2.4" diff --git a/scraper/wrapper.py b/scraper/wrapper.py index 987dd7c..ec447e9 100644 --- a/scraper/wrapper.py +++ b/scraper/wrapper.py @@ -6,21 +6,23 @@ from .exceptions import ScraperException SELF_DIR = os.path.dirname(os.path.abspath(__file__)) +NODE_DIR = os.path.join(SELF_DIR, 'node_modules', 'google-play-scraper') logger = logging.getLogger('__main__') # Private module class. class _Wrapper: - require_dir = os.path.join(SELF_DIR, 'node_modules', 'google-play-scraper') + node_dir = [x if x != '' else os.path.sep for x in NODE_DIR.split(os.path.sep)] + require_dir = "'{}'".format("', '".join(node_dir)) api_script = ( - "var gplay = require('{}'){};" + "var gplay = require(path.join({})){};" "gplay.{}({{{}}})" ".then(JSON.stringify).then(console.log).catch(console.log);" ) var_script = ( - "var gplay = require('{}'){};" + "var gplay = require(path.join({})){};" "let x = gplay.{};" "console.log(JSON.stringify(x));" ) @@ -32,11 +34,13 @@ def __init__(self, memoization=False, vars=[]): def _execute_api(self, fn_name, keys, **kwargs): cmd = self._get_args(keys, **kwargs) - script = self.api_script.format(self.require_dir, self.memoization, fn_name, cmd) + script = self.api_script.format( + self.require_dir, self.memoization, fn_name, cmd) return self._execute(script) def _execute_var(self, var_name): - script = self.var_script.format(self.require_dir, self.memoization, var_name) + script = self.var_script.format( + self.require_dir, self.memoization, var_name) return self._execute(script) def _execute(self, script): @@ -50,7 +54,7 @@ def _execute(self, script): stdout = process.stdout.decode() try: return json.loads(stdout) - except json.decoder.JSONDecodeError as e: + except json.decoder.JSONDecodeError: raise ScraperException(stdout) from None def _get_args(self, keys, **kwargs): @@ -63,9 +67,11 @@ def stringify(x): return '{}'.format(str(x).lower()) return '{}'.format(x) - args = ', '.join(["{}: {}".format(k, stringify(v)) for k, v in kwargs.items() if k in keys + ['throttle']]) + args = ', '.join(["{}: {}".format(k, stringify(v)) + for k, v in kwargs.items() if k in keys + ['throttle']]) return args + # Private module attributes. _wrapper = _Wrapper(vars=['collection', 'category', 'age', 'sort']) @@ -81,6 +87,7 @@ def app(appId, **kwargs): output = _wrapper._execute_api('app', keys, **{'appId': appId, **kwargs}) return output + def list(**kwargs): keys = [ 'collection', 'category', 'age', 'num', @@ -89,6 +96,7 @@ def list(**kwargs): output = _wrapper._execute_api('list', keys, **kwargs) return output + def search(term, **kwargs): keys = [ 'term', 'num', 'lang', @@ -97,34 +105,45 @@ def search(term, **kwargs): output = _wrapper._execute_api('search', keys, **{'term': term, **kwargs}) return output + def developer(devId, **kwargs): keys = ['devId', 'lang', 'country', 'num', 'fullDetail'] - output = _wrapper._execute_api('developer', keys, **{'devId': devId, **kwargs}) + output = _wrapper._execute_api( + 'developer', keys, **{'devId': devId, **kwargs}) return output + def suggest(term, **kwargs): keys = ['term', 'lang', 'country'] - output = _wrapper._execute_api('suggest', keys, **{'term': term, **kwargs}) + output = _wrapper._execute_api( + 'suggest', keys, **{'term': term, **kwargs}) return output + def reviews(appId, **kwargs): keys = [ 'appId', 'lang', 'country', 'sort', 'num', 'paginate', 'nextPaginationToken' ] - output = _wrapper._execute_api('reviews', keys, **{'appId': appId, **kwargs}) + output = _wrapper._execute_api( + 'reviews', keys, **{'appId': appId, **kwargs}) return output + def similar(appId, **kwargs): keys = ['appId', 'lang', 'country', 'fullDetail'] - output = _wrapper._execute_api('similar', keys, **{'appId': appId, **kwargs}) + output = _wrapper._execute_api( + 'similar', keys, **{'appId': appId, **kwargs}) return output + def permissions(appId, **kwargs): keys = ['appId', 'lang', 'short'] - output = _wrapper._execute_api('permissions', keys, **{'appId': appId, **kwargs}) + output = _wrapper._execute_api( + 'permissions', keys, **{'appId': appId, **kwargs}) return output + def categories(**kwargs): output = _wrapper._execute_api('categories', [], **kwargs) return output diff --git a/setup.py b/setup.py index 54d0851..9419b9e 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ setup( name='google-play-scraper-py', - version='0.2.3', + version='0.2.4', description='Scrape application data from the Google Play store.', long_description=long_description, long_description_content_type='text/markdown',