if (len(sys.argv) >= 3): ctr = sys.argv[2] if (len(sys.argv) >= 4): nb_results = sys.argv[3] if (len(sys.argv) == 5): offset = sys.argv[4] # read config from config.py config = GooglePlayAPI.read_config() # connect to GooglePlayStore api = GooglePlayAPI(config['ANDROID_ID']) api.login(config['GOOGLE_LOGIN'], config['GOOGLE_PASSWORD'], config['AUTH_TOKEN']) try: message = api.list(cat, ctr, nb_results, offset) except: print("Error: HTTP 500 - one of the provided parameters is invalid") sys.exit(1) if (ctr is None): print("Subcategory ID", "Name", sep=config['SEPARATOR']) for doc in message.doc: print(helpers.str_compat(doc.docid), helpers.str_compat(doc.title), sep=config['SEPARATOR']) else: helpers.print_header_line() doc = message.doc[0] for c in doc.child: helpers.print_result_line(c)
ctr = sys.argv[2] if (len(sys.argv) >= 4): nb_results = sys.argv[3] if (len(sys.argv) == 5): offset = sys.argv[4] # read config from config.py config = GooglePlayAPI.read_config() # connect to GooglePlayStore api = GooglePlayAPI(config['ANDROID_ID']) api.login(config['GOOGLE_LOGIN'], config['GOOGLE_PASSWORD'], config['AUTH_TOKEN']) try: message = api.list(cat, ctr, nb_results, offset) except: print("Error: HTTP 500 - one of the provided parameters is invalid") sys.exit(1) if (ctr is None): print("Subcategory ID", "Name", sep=config['SEPARATOR']) for doc in message.doc: print(helpers.str_compat(doc.docid), helpers.str_compat(doc.title), sep=config['SEPARATOR']) else: helpers.print_header_line() doc = message.doc[0] for c in doc.child: helpers.print_result_line(c)
class PlayStoreCrawler: def __init__(self): try: creds = loadPlayStoreConfig() self.googleLogin = creds['GOOGLE_LOGIN'] self.googlePassword = creds['GOOGLE_PASSWORD'] self.androidID = creds['ANDROID_ID'] self.authToken = creds['AUTH_TOKEN'] self.api = GooglePlayAPI(self.androidID) # Login to the Play Store except Exception as e: prettyPrintError(e) def login(self): """ Logs into the Google account using the received Google credentials """ try: self.api.login(self.googleLogin, self.googlePassword, self.authToken) except Exception as e: prettyPrintError(e) return False return True def getCategories(self): """ Returns a list of app categories available on Google Play Store """ try: cats = self.api.browse() categories = [c.dataUrl[c.dataUrl.rfind('=')+1:] for c in cats.category] except Exception as e: prettyPrintError(e) return [] return categories def getSubCategories(self, category): """ Returns a list of app sub-categories available on Google Play Store """ try: sub = self.api.list(category) subcategories = [s.docid for s in sub.doc] except Exception as e: prettyPrintError(e) return [] return subcategories def getApps(self, category, subcategory): """ Returns a list of "App" objects found under the given (sub)category """ try: apps = self.api.list(category, subcategory) if len(apps.doc) < 1: prettyPrint("Unable to find any apps under \"%s\" > \"%s\"" % (category, subcategory), "warning") return [] applications = [App(a.title, a.docid, a.details.appDetails.versionCode, a.offer[0].offerType, a.aggregateRating.starRating, a.offer[0].formattedAmount, a.details.appDetails.installationSize) for a in apps.doc[0].child] except Exception as e: prettyPrintError(e) return [] return applications def downloadApp(self, application): """ Downloads an app from the Google play store and moves it to the "downloads" directory """ try: if application.appPrice != "Free": prettyPrint("Warning, downloading a non free application", "warning") # Download the app data = self.api.download(application.appID, application.appVersionCode, application.appOfferType) io.open("%s.apk" % application.appID, "wb").write(data) downloadedApps = glob.glob("./*.apk") dstDir = loadDirs()["DOWNLOADS_DIR"] for da in downloadedApps: shutil.move(da, dstDir) except Exception as e: prettyPrintError(e) return False return True