Skip to content

Commit

Permalink
Fix bug for paths on Windows; bump to 0.2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
nsamarin committed Feb 4, 2022
1 parent b4a9881 commit 6c74b0e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 14 deletions.
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.3"
__version__ = "0.2.4"
43 changes: 31 additions & 12 deletions scraper/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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));"
)
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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'])

Expand All @@ -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',
Expand All @@ -89,6 +96,7 @@ def list(**kwargs):
output = _wrapper._execute_api('list', keys, **kwargs)
return output


def search(term, **kwargs):
keys = [
'term', 'num', 'lang',
Expand All @@ -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
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.3',
version='0.2.4',
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 6c74b0e

Please sign in to comment.