Python code linting and cleanup

This commit is contained in:
Domenico Iezzi 2017-11-07 14:02:23 +01:00
parent e37daed28b
commit 639c7f9e98
No known key found for this signature in database
GPG Key ID: 7AC94D5DDA2FB7EE
3 changed files with 57 additions and 64 deletions

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
__pycache__/ __pycache__/
.ropeproject/
*.swp *.swp
*.apk *.apk
*.obb *.obb

View File

@ -8,7 +8,7 @@ from Crypto.Cipher import PKCS1_OAEP
from clint.textui import progress from clint.textui import progress
import requests import requests
import base64 from base64 import b64decode, urlsafe_b64encode
from itertools import chain from itertools import chain
from . import googleplay_pb2, config, utils from . import googleplay_pb2, config, utils
@ -57,7 +57,7 @@ class GooglePlayAPI(object):
"""Encrypt the password using the google publickey, using """Encrypt the password using the google publickey, using
the RSA encryption algorithm""" the RSA encryption algorithm"""
binaryKey = base64.b64decode(config.GOOGLE_PUBKEY) binaryKey = b64decode(config.GOOGLE_PUBKEY)
i = utils.readInt(binaryKey, 0) i = utils.readInt(binaryKey, 0)
modulus = utils.toBigInt(binaryKey[4:][0:i]) modulus = utils.toBigInt(binaryKey[4:][0:i])
j = utils.readInt(binaryKey, i+4) j = utils.readInt(binaryKey, i+4)
@ -72,7 +72,7 @@ class GooglePlayAPI(object):
combined = login.encode() + b'\x00' + passwd.encode() combined = login.encode() + b'\x00' + passwd.encode()
encrypted = cipher.encrypt(combined) encrypted = cipher.encrypt(combined)
h = b'\x00' + SHA.new(binaryKey).digest()[0:4] h = b'\x00' + SHA.new(binaryKey).digest()[0:4]
return base64.urlsafe_b64encode(h + encrypted) return urlsafe_b64encode(h + encrypted)
def setAuthSubToken(self, authSubToken): def setAuthSubToken(self, authSubToken):
self.authSubToken = authSubToken self.authSubToken = authSubToken
@ -83,13 +83,11 @@ class GooglePlayAPI(object):
def getDefaultHeaders(self): def getDefaultHeaders(self):
"""Return the default set of request headers, which """Return the default set of request headers, which
can later be updated, based on the request type""" can later be expanded, based on the request type"""
headers = { headers = {"Accept-Language": self.deviceBuilder.locale.replace('_', '-'),
"Accept-Language": self.deviceBuilder.locale.replace('_', '-'), "X-DFE-Encoded-Targets": config.DFE_TARGETS,
"X-DFE-Encoded-Targets": config.DFE_TARGETS, "User-Agent": self.deviceBuilder.getUserAgent()}
"User-Agent": self.deviceBuilder.getUserAgent()
}
if self.gsfId is not None: if self.gsfId is not None:
headers["X-DFE-Device-Id"] = "{0:x}".format(self.gsfId) headers["X-DFE-Device-Id"] = "{0:x}".format(self.gsfId)
if self.authSubToken is not None: if self.authSubToken is not None:
@ -122,8 +120,8 @@ class GooglePlayAPI(object):
return response.androidId return response.androidId
def uploadDeviceConfig(self): def uploadDeviceConfig(self):
"""Upload the device configuration defined in the file """Upload the device configuration of the fake device
*device.properties* to the google account. Default device is a Google Nexus 6P""" selected in the __init__ methodi to the google account."""
upload = googleplay_pb2.UploadDeviceConfigRequest() upload = googleplay_pb2.UploadDeviceConfigRequest()
upload.deviceConfiguration.CopyFrom(self.deviceBuilder.getDeviceConfig()) upload.deviceConfiguration.CopyFrom(self.deviceBuilder.getDeviceConfig())
@ -227,7 +225,9 @@ class GooglePlayAPI(object):
previousParams['google_play_services_version'] = '11518448' previousParams['google_play_services_version'] = '11518448'
previousParams.pop('Email') previousParams.pop('Email')
previousParams.pop('EncryptedPasswd') previousParams.pop('EncryptedPasswd')
response = requests.post(self.AUTHURL, data=previousParams, verify=ssl_verify) response = requests.post(self.AUTHURL,
data=previousParams,
verify=ssl_verify)
data = response.text.split() data = response.text.split()
if self.debug: if self.debug:
self.lastResponseText = response.text self.lastResponseText = response.text

View File

@ -5,58 +5,50 @@ VERSION = sys.version_info[0]
def fromDocToDictionary(app): def fromDocToDictionary(app):
return { return {"docId": app.docid,
"docId": app.docid, "title": app.title,
"title": app.title, "author": app.creator,
"author": app.creator, "offer": [{"micros": o.micros,
"offer": [{ "currencyCode": o.currencyCode,
"micros": o.micros, "formattedAmount": o.formattedAmount,
"currencyCode": o.currencyCode, "checkoutFlowRequired": o.checkoutFlowRequired,
"formattedAmount": o.formattedAmount, "offerType": o.offerType}
"checkoutFlowRequired": o.checkoutFlowRequired, for o in app.offer],
"offerType": o.offerType "images": [{"imageType": img.imageType,
} for o in app.offer], "width": img.dimension.width
"images": [{ if hasattr(img.dimension, "width")
"imageType": img.imageType, else 0,
"width": img.dimension.width if hasattr(img.dimension, "width") "height": img.dimension.height
else 0, if hasattr(img.dimension, "height")
"height": img.dimension.height if hasattr(img.dimension, "height") else 0,
else 0, "url": img.imageUrl,
"url": img.imageUrl, "supportsFifeUrlOptions": img.supportsFifeUrlOptions}
"supportsFifeUrlOptions": img.supportsFifeUrlOptions for img in app.image],
} for img in app.image], "versionCode": app.details.appDetails.versionCode,
"versionCode": app.details.appDetails.versionCode, "installationSize": app.details.appDetails.installationSize,
"installationSize": app.details.appDetails.installationSize, "numDownloads": app.details.appDetails.numDownloads,
"numDownloads": app.details.appDetails.numDownloads, "uploadDate": app.details.appDetails.uploadDate,
"uploadDate": app.details.appDetails.uploadDate, "files": [{"fileType": f.fileType,
"files": [{ "version": f.versionCode,
"fileType": f.fileType, "size": f.size}
"version": f.versionCode, for f in app.details.appDetails.file],
"size": f.size "unstable": app.details.appDetails.unstable,
} for f in app.details.appDetails.file], "containsAds": app.details.appDetails.containsAds,
"unstable": app.details.appDetails.unstable, "aggregateRating": {"type": app.aggregateRating.type,
"containsAds": app.details.appDetails.containsAds, "starRating": app.aggregateRating.starRating,
"aggregateRating": { "ratingsCount": app.aggregateRating.ratingsCount,
"type": app.aggregateRating.type, "oneStarRatings": app.aggregateRating.oneStarRatings,
"starRating": app.aggregateRating.starRating, "twoStarRatings": app.aggregateRating.twoStarRatings,
"ratingsCount": app.aggregateRating.ratingsCount, "threeStarRatings": app.aggregateRating.threeStarRatings,
"oneStarRatings": app.aggregateRating.oneStarRatings, "fourStarRatings": app.aggregateRating.fourStarRatings,
"twoStarRatings": app.aggregateRating.twoStarRatings, "fiveStarRatings": app.aggregateRating.fiveStarRatings,
"threeStarRatings": app.aggregateRating.threeStarRatings, "commentCount": app.aggregateRating.commentCount},
"fourStarRatings": app.aggregateRating.fourStarRatings, "dependencies": [{"packageName": d.packageName,
"fiveStarRatings": app.aggregateRating.fiveStarRatings, "version": d.version}
"commentCount": app.aggregateRating.commentCount for d in app.details.appDetails.dependencies.dependency],
}, "category": {"appType": app.relatedLinks.categoryInfo.appType,
"dependencies": [{ "appCategory": app.relatedLinks.categoryInfo.appCategory},
"packageName": d.packageName, "detailsUrl": app.detailsUrl}
"version": d.version
} for d in app.details.appDetails.dependencies.dependency],
"category": {
"appType": app.relatedLinks.categoryInfo.appType,
"appCategory": app.relatedLinks.categoryInfo.appCategory
},
"detailsUrl": app.detailsUrl
}
def readInt(byteArray, start): def readInt(byteArray, start):