From 4ad93046ba0998ae475d7027bc154e8ba0583264 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Sun, 25 Nov 2012 23:26:13 -0600 Subject: [PATCH 1/5] turn this into a basic python egg --- .gitignore | 3 +++ googleplayapi/__init__.py | 0 apishell.py => googleplayapi/apishell.py | 0 categories.py => googleplayapi/categories.py | 0 config.py => googleplayapi/config.py | 0 download.py => googleplayapi/download.py | 0 googleplay.proto => googleplayapi/googleplay.proto | 0 googleplay.py => googleplayapi/googleplay.py | 0 googleplay_pb2.py => googleplayapi/googleplay_pb2.py | 0 helpers.py => googleplayapi/helpers.py | 0 list.py => googleplayapi/list.py | 0 permissions.py => googleplayapi/permissions.py | 0 search.py => googleplayapi/search.py | 0 setup.py | 12 ++++++++++++ 14 files changed, 15 insertions(+) create mode 100644 googleplayapi/__init__.py rename apishell.py => googleplayapi/apishell.py (100%) rename categories.py => googleplayapi/categories.py (100%) rename config.py => googleplayapi/config.py (100%) rename download.py => googleplayapi/download.py (100%) rename googleplay.proto => googleplayapi/googleplay.proto (100%) rename googleplay.py => googleplayapi/googleplay.py (100%) rename googleplay_pb2.py => googleplayapi/googleplay_pb2.py (100%) rename helpers.py => googleplayapi/helpers.py (100%) rename list.py => googleplayapi/list.py (100%) rename permissions.py => googleplayapi/permissions.py (100%) rename search.py => googleplayapi/search.py (100%) create mode 100644 setup.py diff --git a/.gitignore b/.gitignore index 19767b9..00041d0 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,6 @@ # ignore downloaded apps *.apk + +# ignore egg build leftovers +build/ diff --git a/googleplayapi/__init__.py b/googleplayapi/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/apishell.py b/googleplayapi/apishell.py similarity index 100% rename from apishell.py rename to googleplayapi/apishell.py diff --git a/categories.py b/googleplayapi/categories.py similarity index 100% rename from categories.py rename to googleplayapi/categories.py diff --git a/config.py b/googleplayapi/config.py similarity index 100% rename from config.py rename to googleplayapi/config.py diff --git a/download.py b/googleplayapi/download.py similarity index 100% rename from download.py rename to googleplayapi/download.py diff --git a/googleplay.proto b/googleplayapi/googleplay.proto similarity index 100% rename from googleplay.proto rename to googleplayapi/googleplay.proto diff --git a/googleplay.py b/googleplayapi/googleplay.py similarity index 100% rename from googleplay.py rename to googleplayapi/googleplay.py diff --git a/googleplay_pb2.py b/googleplayapi/googleplay_pb2.py similarity index 100% rename from googleplay_pb2.py rename to googleplayapi/googleplay_pb2.py diff --git a/helpers.py b/googleplayapi/helpers.py similarity index 100% rename from helpers.py rename to googleplayapi/helpers.py diff --git a/list.py b/googleplayapi/list.py similarity index 100% rename from list.py rename to googleplayapi/list.py diff --git a/permissions.py b/googleplayapi/permissions.py similarity index 100% rename from permissions.py rename to googleplayapi/permissions.py diff --git a/search.py b/googleplayapi/search.py similarity index 100% rename from search.py rename to googleplayapi/search.py diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..eb538c2 --- /dev/null +++ b/setup.py @@ -0,0 +1,12 @@ +from setuptools import setup, find_packages + +version = "1.0.0" + +setup(name="googleplayapi", + version=version, + author="Emilien Girault", + author_email="emilien.girault@gmail.com", + license="BSD", + description="Google Play API for Android", + url="https://github.com/kanzure/googleplay-api", + packages=find_packages()) From bfa35f0212a50a4a5ffd9a6c4ddf22b22d3abbd7 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Sun, 25 Nov 2012 23:27:13 -0600 Subject: [PATCH 2/5] use absolute imports to refer to package --- googleplayapi/apishell.py | 4 ++-- googleplayapi/categories.py | 4 ++-- googleplayapi/download.py | 6 +++--- googleplayapi/googleplay.py | 4 ++-- googleplayapi/helpers.py | 2 +- googleplayapi/list.py | 6 +++--- googleplayapi/permissions.py | 4 ++-- googleplayapi/search.py | 6 +++--- 8 files changed, 18 insertions(+), 18 deletions(-) diff --git a/googleplayapi/apishell.py b/googleplayapi/apishell.py index ad0db2e..7120508 100755 --- a/googleplayapi/apishell.py +++ b/googleplayapi/apishell.py @@ -15,8 +15,8 @@ from pprint import pprint from google.protobuf import text_format -from config import * -from googleplay import GooglePlayAPI +from googleplayapi.config import * +from googleplayapi.googleplay import GooglePlayAPI api = GooglePlayAPI(ANDROID_ID) api.login(GOOGLE_LOGIN, GOOGLE_PASSWORD, AUTH_TOKEN) diff --git a/googleplayapi/categories.py b/googleplayapi/categories.py index e946215..ec65a13 100755 --- a/googleplayapi/categories.py +++ b/googleplayapi/categories.py @@ -8,8 +8,8 @@ from pprint import pprint from google.protobuf import text_format -from config import * -from googleplay import GooglePlayAPI +from googleplayapi.config import * +from googleplayapi.googleplay import GooglePlayAPI api = GooglePlayAPI(ANDROID_ID) api.login(GOOGLE_LOGIN, GOOGLE_PASSWORD, AUTH_TOKEN) diff --git a/googleplayapi/download.py b/googleplayapi/download.py index 7a6ba42..70aec54 100755 --- a/googleplayapi/download.py +++ b/googleplayapi/download.py @@ -6,9 +6,9 @@ import sys from pprint import pprint -from config import * -from googleplay import GooglePlayAPI -from helpers import sizeof_fmt +from googleplayapi.config import * +from googleplayapi.googleplay import GooglePlayAPI +from googleplayapi.helpers import sizeof_fmt if (len(sys.argv) < 2): print "Usage: %s packagename [filename]" diff --git a/googleplayapi/googleplay.py b/googleplayapi/googleplay.py index a17f7f9..fb71ff5 100644 --- a/googleplayapi/googleplay.py +++ b/googleplayapi/googleplay.py @@ -11,8 +11,8 @@ from google.protobuf import text_format from google.protobuf.message import Message, DecodeError -import googleplay_pb2 -import config +import googleplayapi.googleplay_pb2 as googleplay_pb2 +import googleplayapi.config as config class LoginError(Exception): def __init__(self, value): diff --git a/googleplayapi/helpers.py b/googleplayapi/helpers.py index 2c1fa9c..a745dfa 100644 --- a/googleplayapi/helpers.py +++ b/googleplayapi/helpers.py @@ -1,4 +1,4 @@ -from config import SEPARATOR +from googleplayapi.config import SEPARATOR def sizeof_fmt(num): for x in ['bytes','KB','MB','GB','TB']: diff --git a/googleplayapi/list.py b/googleplayapi/list.py index 97bccc3..fb7f4ec 100755 --- a/googleplayapi/list.py +++ b/googleplayapi/list.py @@ -6,9 +6,9 @@ import sys from pprint import pprint -from config import * -from googleplay import GooglePlayAPI -from helpers import sizeof_fmt, print_header_line, print_result_line +from googleplayapi.config import * +from googleplayapi.googleplay import GooglePlayAPI +from googleplayapi.helpers import sizeof_fmt, print_header_line, print_result_line if (len(sys.argv) < 2): print "Usage: %s category [subcategory] [nb_results] [offset]" % sys.argv[0] diff --git a/googleplayapi/permissions.py b/googleplayapi/permissions.py index 5843458..6f841e3 100755 --- a/googleplayapi/permissions.py +++ b/googleplayapi/permissions.py @@ -8,8 +8,8 @@ from pprint import pprint from google.protobuf import text_format -from config import * -from googleplay import GooglePlayAPI +from googleplayapi.config import * +from googleplayapi.googleplay import GooglePlayAPI if (len(sys.argv) < 2): print "Usage: %s packagename1 [packagename2 [...]]" % sys.argv[0] diff --git a/googleplayapi/search.py b/googleplayapi/search.py index abfa8e9..7defcba 100755 --- a/googleplayapi/search.py +++ b/googleplayapi/search.py @@ -6,9 +6,9 @@ import sys from pprint import pprint -from config import * -from googleplay import GooglePlayAPI -from helpers import sizeof_fmt, print_header_line, print_result_line +from googleplayapi.config import * +from googleplayapi.googleplay import GooglePlayAPI +from googleplayapi.helpers import sizeof_fmt, print_header_line, print_result_line if (len(sys.argv) < 2): print "Usage: %s request [nb_results] [offset]" % sys.argv[0] From a391289c1a960397df282d5e88fda78d294c636b Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Sun, 25 Nov 2012 23:41:27 -0600 Subject: [PATCH 3/5] somewhat deprecate config.py This makes GooglePlayAPI in googleplay.py somewhat more self-reliant by allowing username and password to be given directly to the constructor. The config file is no longer a strict requirement, and multiple projects can rely on the same physical egg or package. --- googleplayapi/download.py | 8 ++++++-- googleplayapi/googleplay.py | 35 +++++++++++++++++++++++++++++++---- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/googleplayapi/download.py b/googleplayapi/download.py index 70aec54..90e6ba0 100755 --- a/googleplayapi/download.py +++ b/googleplayapi/download.py @@ -24,8 +24,12 @@ filename = packagename + ".apk" # Connect -api = GooglePlayAPI(ANDROID_ID) -api.login(GOOGLE_LOGIN, GOOGLE_PASSWORD, AUTH_TOKEN) +api = GooglePlayAPI(androidId=ANDROID_ID, email=GOOGLE_LOGIN, password=GOOGLE_PASSWORD, authSubToken=AUTH_TOKEN) + +# login if necessary +if not AUTH_TOKEN: + # api.login(GOOGLE_LOGIN, GOOGLE_PASSWORD, AUTH_TOKEN) + api.login() # Get the version code and the offer type from the app details m = api.details(packagename) diff --git a/googleplayapi/googleplay.py b/googleplayapi/googleplay.py index fb71ff5..dadf71a 100644 --- a/googleplayapi/googleplay.py +++ b/googleplayapi/googleplay.py @@ -46,12 +46,33 @@ class GooglePlayAPI(object): authSubToken = None context = None - def __init__(self, androidId=None, debug=False): # you must use a device-associated androidId value + def __init__(self, androidId=None, authSubToken=None, email=None, password=None, debug=False): + """Google Play API + + authSubToken - pass in this value instead of calling login() multiple times + + email - Google Play username + + password - Google Play Password + + androidId - device id associated with the same Google Play account + + debug - increase verbosity and clutter up the screen + """ self.preFetch = {} + + self.debug = debug + + # store immediately to avoid more params to login() later + self.email = email + self.password = password + self.authSubToken = authSubToken + + # try to grab androidId from config as a last resort if androidId == None: + import googleplayapi.config as config androidId = config.ANDROID_ID self.androidId = androidId - self.debug = debug def toDict(self, protoObj): """Converts the (protobuf) result from an API call into a dict, for @@ -92,14 +113,20 @@ def _try_register_preFetch(self, protoObj): def setAuthSubToken(self, authSubToken): self.authSubToken = authSubToken - # put your auth token in config.py to avoid multiple login requests if self.debug: print "authSubToken: " + authSubToken def login(self, email=None, password=None, authSubToken=None): - """Login to your Google Account. You must provide either: + """Login to your Google account. You must provide either: - an email and password - a valid Google authSubToken""" + if email == None: + email = self.email + if password == None: + password = self.password + # Don't load authSubToken from self because maybe we're logging in + # again. + if (authSubToken is not None): self.setAuthSubToken(authSubToken) else: From 820ce515d30b4ed389b15b759d4ceb2de7187ab4 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Sun, 25 Nov 2012 23:44:42 -0600 Subject: [PATCH 4/5] remove "DO NOT REMOVE" lines --- googleplayapi/apishell.py | 3 --- googleplayapi/categories.py | 3 --- googleplayapi/download.py | 3 --- googleplayapi/list.py | 3 --- googleplayapi/permissions.py | 3 --- googleplayapi/search.py | 3 --- 6 files changed, 18 deletions(-) diff --git a/googleplayapi/apishell.py b/googleplayapi/apishell.py index 7120508..8688cb1 100755 --- a/googleplayapi/apishell.py +++ b/googleplayapi/apishell.py @@ -1,8 +1,5 @@ #!/usr/bin/python -# Do not remove -GOOGLE_LOGIN = GOOGLE_PASSWORD = AUTH_TOKEN = None - BANNER = """ Google Play Unofficial API Interactive Shell Successfully logged in using your Google account. The variable 'api' holds the API object. diff --git a/googleplayapi/categories.py b/googleplayapi/categories.py index ec65a13..591e349 100755 --- a/googleplayapi/categories.py +++ b/googleplayapi/categories.py @@ -1,8 +1,5 @@ #!/usr/bin/python -# Do not remove -GOOGLE_LOGIN = GOOGLE_PASSWORD = AUTH_TOKEN = None - import sys import urlparse from pprint import pprint diff --git a/googleplayapi/download.py b/googleplayapi/download.py index 90e6ba0..1f727d8 100755 --- a/googleplayapi/download.py +++ b/googleplayapi/download.py @@ -1,8 +1,5 @@ #!/usr/bin/python -# Do not remove -GOOGLE_LOGIN = GOOGLE_PASSWORD = AUTH_TOKEN = None - import sys from pprint import pprint diff --git a/googleplayapi/list.py b/googleplayapi/list.py index fb7f4ec..bc2b978 100755 --- a/googleplayapi/list.py +++ b/googleplayapi/list.py @@ -1,8 +1,5 @@ #!/usr/bin/python -# Do not remove -GOOGLE_LOGIN = GOOGLE_PASSWORD = AUTH_TOKEN = None - import sys from pprint import pprint diff --git a/googleplayapi/permissions.py b/googleplayapi/permissions.py index 6f841e3..0f0a583 100755 --- a/googleplayapi/permissions.py +++ b/googleplayapi/permissions.py @@ -1,8 +1,5 @@ #!/usr/bin/python -# Do not remove -GOOGLE_LOGIN = GOOGLE_PASSWORD = AUTH_TOKEN = None - import sys import urlparse from pprint import pprint diff --git a/googleplayapi/search.py b/googleplayapi/search.py index 7defcba..0450541 100755 --- a/googleplayapi/search.py +++ b/googleplayapi/search.py @@ -1,8 +1,5 @@ #!/usr/bin/python -# Do not remove -GOOGLE_LOGIN = GOOGLE_PASSWORD = AUTH_TOKEN = None - import sys from pprint import pprint From f8af4de21ea1d266f9ca7610f1f324a070e201de Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Sun, 25 Nov 2012 23:46:41 -0600 Subject: [PATCH 5/5] switch from FR to US --- googleplayapi/googleplay.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/googleplayapi/googleplay.py b/googleplayapi/googleplay.py index dadf71a..ac16bdc 100644 --- a/googleplayapi/googleplay.py +++ b/googleplayapi/googleplay.py @@ -141,9 +141,9 @@ def login(self, email=None, password=None, authSubToken=None): "androidId": self.androidId, "app": "com.android.vending", #"client_sig": self.client_sig, - "device_country": "fr", - "operatorCountry": "fr", - "lang": "fr", + "device_country": "us", + "operatorCountry": "us", + "lang": "en", "sdk_version": "16"} headers = { "Accept-Encoding": "",