From 0a5e2700494568f17dace1f1e4a11892f90da7fb Mon Sep 17 00:00:00 2001 From: Domenico Iezzi Date: Wed, 4 Oct 2017 13:42:52 +0200 Subject: [PATCH] Improved python2 compatibility Signed-off-by: Domenico Iezzi --- .travis.yml | 4 +++- README.md | 6 +++--- gpapi/config.py | 14 ++++++++++++-- gpapi/utils.py | 8 +++++++- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 23060e8..55a4a91 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,6 @@ language: python -python: '3.6' +python: + - "2.7" + - "3.5" install: pip install . script: python test.py diff --git a/README.md b/README.md index 5190909..351dab3 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ -# Google play python3 API [![Build Status](https://travis-ci.org/NoMore201/googleplay-api.svg?branch=master)](https://travis-ci.org/NoMore201/googleplay-api) +# Google play python API [![Build Status](https://travis-ci.org/NoMore201/googleplay-api.svg?branch=master)](https://travis-ci.org/NoMore201/googleplay-api) This project contains an unofficial API for google play interactions. The code mainly comes from -[GooglePlayAPI project](https://github.com/egirault/googleplay-api/) which was written for python2 and it's not -maintained anymore. The code was ported to python3 with some important changes: +[GooglePlayAPI project](https://github.com/egirault/googleplay-api/) which is not +maintained anymore. The code was updated with some important changes: * ac2dm authentication with checkin and device info upload * updated search and download calls diff --git a/gpapi/config.py b/gpapi/config.py index e588ead..6f9b13f 100644 --- a/gpapi/config.py +++ b/gpapi/config.py @@ -1,7 +1,13 @@ from . import googleplay_pb2 import time import os -import configparser +import sys + +VERSION = sys.version_info[0] +if VERSION == 2: + import ConfigParser +else: + import configparser # separator used by search.py, categories.py, ... SEPARATOR = ";" @@ -13,7 +19,11 @@ GOOGLE_PUBKEY = "AAAAgMom/1a/v0lblO2Ubrt60J2gcuXSljGFQXgcyZWveWLEwo6prwgi3iJIZ # if you want to add another phone, just create another section in # the file. Some configurations for common phones can be found here: # https://github.com/yeriomin/play-store-api/tree/master/src/main/resources -config = configparser.ConfigParser() +if VERSION == 2: + config = ConfigParser.ConfigParser() +else: + config = configparser.ConfigParser() + filepath = os.path.join( os.path.dirname( os.path.realpath(__file__) ), 'device.properties') config.read(filepath) device = {} diff --git a/gpapi/utils.py b/gpapi/utils.py index 854deb0..e724f35 100644 --- a/gpapi/utils.py +++ b/gpapi/utils.py @@ -1,4 +1,7 @@ import struct +import sys + +VERSION = sys.version_info[0] def fromDocToDictionary(app): return { @@ -65,6 +68,9 @@ def toBigInt(byteArray): array = byteArray[::-1] # reverse array out = 0 for key, value in enumerate(array): - decoded = struct.unpack("B", bytes([value]))[0] + if VERSION == 3: + decoded = struct.unpack("B", bytes([value]))[0] + else: + decoded = struct.unpack("B", value)[0] out = out | decoded << key*8 return out