Skip to content

Commit

Permalink
more formatting changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kanzure committed Nov 26, 2012
1 parent fedbcd1 commit 9e2f658
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions googleplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,14 @@ class GooglePlayAPI(object):
authSubToken = None
context = None

def __init__(self, androidId): # Search results may depend on the following parameters, so try to pick real ones.
def __init__(self, androidId, debug=True): # you must use a device-associated androidId value
self.preFetch = {}
self.androidId = androidId
self.debug = debug

def toDict(self, protoObj):
"""Converts the (protobuf) result from an API call into a dict, for easier introspection."""
"""Converts the (protobuf) result from an API call into a dict, for
easier introspection."""
iterable = False
if isinstance(protoObj, RepeatedCompositeFieldContainer):
iterable = True
Expand All @@ -63,7 +65,7 @@ def toDict(self, protoObj):
for po in protoObj:
msg = dict()
for fielddesc, value in po.ListFields():
#print value, type(value), getattr(value, '__iter__', False)
#print value, type(value), getattr(value, "__iter__", False)
if fielddesc.type == descriptor.FieldDescriptor.TYPE_GROUP or isinstance(value, RepeatedCompositeFieldContainer) or isinstance(value, google.protobuf.message.Message):
msg[fielddesc.name] = self.toDict(value)
else:
Expand All @@ -89,14 +91,14 @@ def _try_register_preFetch(self, protoObj):
def setAuthSubToken(self, authSubToken):
self.authSubToken = authSubToken

# Uncomment this line to print your auth token, and put it in config.py for faster access
# print 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):
def login(self, email=None, password=None, authSubToken=None):
"""Login to your Google Account. You must provide either:
- an email and password
- a valid Google authSubToken
"""
- a valid Google authSubToken"""
if (authSubToken is not None):
self.setAuthSubToken(authSubToken)
else:
Expand Down Expand Up @@ -142,7 +144,6 @@ def login(self, email=None, password=None, authSubToken = None):
raise e

def executeRequestApi2(self, path, datapost=None, post_content_type="application/x-www-form-urlencoded; charset=UTF-8"):

if (datapost is None and path in self.preFetch):
data = self.preFetch[path]
else:
Expand Down Expand Up @@ -242,8 +243,9 @@ def download(self, packageName, versionCode, offerType=1):
"""Download an app and return its raw data (APK file).
packageName is the app unique ID (usually starting with 'com.').
versionCode can be grabbed by using the details() method on the given app."""
versionCode can be grabbed by using the details() method on the given
app."""
path = "purchase"
data = "ot=%d&doc=%s&vc=%d" % (offerType, packageName, versionCode)
message = self.executeRequestApi2(path, data)
Expand Down

0 comments on commit 9e2f658

Please sign in to comment.