2017-09-18 14:33:11 +00:00
|
|
|
import struct
|
2017-10-04 11:42:52 +00:00
|
|
|
import sys
|
|
|
|
|
|
|
|
VERSION = sys.version_info[0]
|
2017-09-18 14:33:11 +00:00
|
|
|
|
2017-10-10 16:35:40 +00:00
|
|
|
|
2017-09-18 14:33:11 +00:00
|
|
|
def fromDocToDictionary(app):
|
2017-11-07 13:02:23 +00:00
|
|
|
return {"docId": app.docid,
|
|
|
|
"title": app.title,
|
|
|
|
"author": app.creator,
|
|
|
|
"offer": [{"micros": o.micros,
|
|
|
|
"currencyCode": o.currencyCode,
|
|
|
|
"formattedAmount": o.formattedAmount,
|
|
|
|
"checkoutFlowRequired": o.checkoutFlowRequired,
|
|
|
|
"offerType": o.offerType}
|
|
|
|
for o in app.offer],
|
|
|
|
"images": [{"imageType": img.imageType,
|
|
|
|
"width": img.dimension.width
|
|
|
|
if hasattr(img.dimension, "width")
|
|
|
|
else 0,
|
|
|
|
"height": img.dimension.height
|
|
|
|
if hasattr(img.dimension, "height")
|
|
|
|
else 0,
|
|
|
|
"url": img.imageUrl,
|
|
|
|
"supportsFifeUrlOptions": img.supportsFifeUrlOptions}
|
|
|
|
for img in app.image],
|
|
|
|
"versionCode": app.details.appDetails.versionCode,
|
|
|
|
"installationSize": app.details.appDetails.installationSize,
|
|
|
|
"numDownloads": app.details.appDetails.numDownloads,
|
|
|
|
"uploadDate": app.details.appDetails.uploadDate,
|
|
|
|
"files": [{"fileType": f.fileType,
|
|
|
|
"version": f.versionCode,
|
|
|
|
"size": f.size}
|
|
|
|
for f in app.details.appDetails.file],
|
|
|
|
"unstable": app.details.appDetails.unstable,
|
|
|
|
"containsAds": app.details.appDetails.containsAds,
|
|
|
|
"aggregateRating": {"type": app.aggregateRating.type,
|
|
|
|
"starRating": app.aggregateRating.starRating,
|
|
|
|
"ratingsCount": app.aggregateRating.ratingsCount,
|
|
|
|
"oneStarRatings": app.aggregateRating.oneStarRatings,
|
|
|
|
"twoStarRatings": app.aggregateRating.twoStarRatings,
|
|
|
|
"threeStarRatings": app.aggregateRating.threeStarRatings,
|
|
|
|
"fourStarRatings": app.aggregateRating.fourStarRatings,
|
|
|
|
"fiveStarRatings": app.aggregateRating.fiveStarRatings,
|
|
|
|
"commentCount": app.aggregateRating.commentCount},
|
|
|
|
"dependencies": [{"packageName": d.packageName,
|
|
|
|
"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}
|
2017-09-18 14:33:11 +00:00
|
|
|
|
2017-10-10 16:35:40 +00:00
|
|
|
|
2017-09-18 14:33:11 +00:00
|
|
|
def readInt(byteArray, start):
|
|
|
|
"""Read the byte array, starting from *start* position,
|
|
|
|
as an 32-bit unsigned integer"""
|
|
|
|
return struct.unpack("!L", byteArray[start:][0:4])[0]
|
|
|
|
|
|
|
|
|
|
|
|
def toBigInt(byteArray):
|
|
|
|
"""Convert the byte array to a BigInteger"""
|
2017-10-10 16:35:40 +00:00
|
|
|
array = byteArray[::-1] # reverse array
|
2017-09-18 14:33:11 +00:00
|
|
|
out = 0
|
|
|
|
for key, value in enumerate(array):
|
2017-10-04 11:42:52 +00:00
|
|
|
if VERSION == 3:
|
|
|
|
decoded = struct.unpack("B", bytes([value]))[0]
|
|
|
|
else:
|
|
|
|
decoded = struct.unpack("B", value)[0]
|
2017-10-10 16:35:40 +00:00
|
|
|
out = out | decoded << key * 8
|
2017-09-18 14:33:11 +00:00
|
|
|
return out
|