Created
January 8, 2017 13:20
-
-
Save pn/9a388030709f5a9b7358fc1d8a3a60a9 to your computer and use it in GitHub Desktop.
Given list of Google Play packages, find all similar apps (without repetitions) and their attributes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
var gplay = require('./google-play-scraper'); // download from https://github.com/facundoolano/google-play-scraper | |
// input | |
var main_packages = [ | |
'com.google.android.gm', | |
'com.google.android.apps.inbox', | |
]; // packages to look for similar apps | |
// Outputs unique list of similar apps to given apps | |
output_sep=";"; | |
var results; | |
var main_toProcess = main_packages.length; | |
var packages = main_packages; | |
var toProcess = 0; | |
// from https://stackoverflow.com/questions/11688692/most-elegant-way-to-create-a-list-of-unique-items-in-javascript | |
function unique(arr) { | |
var u = {}, a = []; | |
for(var i = 0, l = arr.length; i < l; ++i){ | |
if(!u.hasOwnProperty(arr[i])) { | |
a.push(arr[i]); | |
u[arr[i]] = 1; | |
} | |
} | |
return a; | |
} | |
function extract(app) { | |
var result = ""; | |
result += app.title + output_sep; | |
result += '' + app.score + output_sep; | |
result += '' + app.reviews + output_sep; | |
result += '' + app.minInstalls + output_sep; | |
result += '' + app.offersIAP + output_sep; | |
result += '' + app.androidVersionText + output_sep; | |
result += '' + app.url; | |
console.log(result); | |
toProcess--; | |
if (toProcess == 0) { | |
process.exit() | |
} | |
} | |
function processPackages() { | |
var packagesUnique = unique(packages); | |
toProcess = packagesUnique.length; | |
console.log("Title;Score;Reviews;Min installs;IAPs;Android version;URL"); | |
for (pkg of packagesUnique) { | |
gplay.app({appId: pkg}).then(extract, console.log); | |
} | |
} | |
function findSimilar(list) { | |
for (sim of list) { | |
packages.push(sim.appId); | |
} | |
main_toProcess--; | |
if (main_toProcess == 0) { | |
processPackages() | |
} | |
} | |
for (pkg of main_packages) { | |
gplay.similar({appId: pkg}).then(findSimilar); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment