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,39 +5,36 @@ 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": [{ "offer": [{"micros": o.micros,
"micros": o.micros,
"currencyCode": o.currencyCode, "currencyCode": o.currencyCode,
"formattedAmount": o.formattedAmount, "formattedAmount": o.formattedAmount,
"checkoutFlowRequired": o.checkoutFlowRequired, "checkoutFlowRequired": o.checkoutFlowRequired,
"offerType": o.offerType "offerType": o.offerType}
} for o in app.offer], for o in app.offer],
"images": [{ "images": [{"imageType": img.imageType,
"imageType": img.imageType, "width": img.dimension.width
"width": img.dimension.width if hasattr(img.dimension, "width") if hasattr(img.dimension, "width")
else 0, else 0,
"height": img.dimension.height 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": [{ "files": [{"fileType": f.fileType,
"fileType": f.fileType,
"version": f.versionCode, "version": f.versionCode,
"size": f.size "size": f.size}
} for f in app.details.appDetails.file], for f in app.details.appDetails.file],
"unstable": app.details.appDetails.unstable, "unstable": app.details.appDetails.unstable,
"containsAds": app.details.appDetails.containsAds, "containsAds": app.details.appDetails.containsAds,
"aggregateRating": { "aggregateRating": {"type": app.aggregateRating.type,
"type": app.aggregateRating.type,
"starRating": app.aggregateRating.starRating, "starRating": app.aggregateRating.starRating,
"ratingsCount": app.aggregateRating.ratingsCount, "ratingsCount": app.aggregateRating.ratingsCount,
"oneStarRatings": app.aggregateRating.oneStarRatings, "oneStarRatings": app.aggregateRating.oneStarRatings,
@ -45,18 +42,13 @@ def fromDocToDictionary(app):
"threeStarRatings": app.aggregateRating.threeStarRatings, "threeStarRatings": app.aggregateRating.threeStarRatings,
"fourStarRatings": app.aggregateRating.fourStarRatings, "fourStarRatings": app.aggregateRating.fourStarRatings,
"fiveStarRatings": app.aggregateRating.fiveStarRatings, "fiveStarRatings": app.aggregateRating.fiveStarRatings,
"commentCount": app.aggregateRating.commentCount "commentCount": app.aggregateRating.commentCount},
}, "dependencies": [{"packageName": d.packageName,
"dependencies": [{ "version": d.version}
"packageName": d.packageName, for d in app.details.appDetails.dependencies.dependency],
"version": d.version "category": {"appType": app.relatedLinks.categoryInfo.appType,
} for d in app.details.appDetails.dependencies.dependency], "appCategory": app.relatedLinks.categoryInfo.appCategory},
"category": { "detailsUrl": app.detailsUrl}
"appType": app.relatedLinks.categoryInfo.appType,
"appCategory": app.relatedLinks.categoryInfo.appCategory
},
"detailsUrl": app.detailsUrl
}
def readInt(byteArray, start): def readInt(byteArray, start):